[Java for Android App Development] mikrosmile:
Add 3 Dot menu to actionbar

For the Menu in actionbar you just implement simple menu method, but you dont need to use menu.xml for it.

Also you dont need to create string values for Menu, it will generate automatically for you, the icon, and the name.

This is method to create Menu in ActionBar. Add it in MainActivity before SetupActionBar() method

public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add("ContextMenu");
}

[MENTION=439709]override[/MENTION]
public boolean onCreateOptionsMenu (Menu menu) {
menu.add(1, 1, 1, R.string.settings);
return true;
}

public boolean onOptionsItemSelected(MenuItem menuitem)
{
boolean flag = true;
switch (menuitem.getItemId())
{
case 1:
startActivity(new Intent(this, Settings.class));
break;
}
return flag;

}

This is your new MainActivity with Menu

package com.yourpackage.name;

import android.content.Intent;
import android.os.Bundle;
import com.htc.widget.CarouselActivity;
import com.htc.widget.CarouselHost;
import com.htc.widget.ActionBarExt;
import com.htc.widget.ActionBarText;
[COLOR="Red"]import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;[/COLOR]

public class MainActivity extends CarouselActivity {
final static String AUTHORITY =
"com.yourpackage.name.TabProvider";
public static ActionBarText mActionText;

public MainActivity() {
super(AUTHORITY);
}

[COLOR="red"]public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add("ContextMenu");
}

[MENTION=439709]override[/MENTION]
public boolean onCreateOptionsMenu (Menu menu) {
menu.add(1, 1, 1, R.string.settings);
return true;
}

public boolean onOptionsItemSelected(MenuItem menuitem)
{
boolean flag = true;
switch (menuitem.getItemId())
{
case 1:
startActivity(new Intent(this, Settings.class));
break;
}
return flag;

}[/COLOR]

private void SetupActionBar()
{
Object obj = new ActionBarExt(this, getActionBar());
((ActionBarExt)obj).setFullScreenEnabled(true);
((ActionBarExt)obj).enableHTCLandscape(false);
mActionText = new ActionBarText(this);
mActionText.setPrimaryText(R.string.app_name);
obj = ((ActionBarExt)obj).getCustomContainer();
((ActionBarContainer)obj).setRightDividerEnabled(true);
((ActionBarContainer)obj).addCenterView(mActionText);
}

[MENTION=439709]override[/MENTION]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setGId(1);
super.onCreate(savedInstanceState);
final CarouselHost mPanelHost = getCarouselHost();
SetupActionBar();

mPanelHost.addTab("Tab1", this, R.string.tab_1,
R.drawable.ic_tab1,
R.drawable.ic_tab1,
R.drawable.ic_tab1,
(new Intent("com.yourpackage.name.Tab1")));
mPanelHost.addTab("Tab2", this, R.string.tab_2,
R.drawable.ic_tab2,
R.drawable.ic_tab2,
R.drawable.ic_tab2,
(new Intent("com.yourpackage.name.Tab2")));
}

}

HTC AlertDialog​

In order to have alertdialog you need to have OnClickListener and inside OnClickListener you paste alertDialog.

public void onItemClick(HtcAdapterView<?> parent, View view, int position, long id) {

[COLOR="red"]HtcAlertDialog.Builder[/COLOR] alertDialog = new [COLOR="red"]HtcAlertDialog.Builder[/COLOR]([B]YourActivity.this[/B]);

alertDialog.setTitle(R.string.title_txt);

alertDialog.setMessage(R.string.message_txt);
alertDialog.setIcon(R.drawable.icon);

alertDialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
//Do your actions here when user click Yes
}
});
alertDialog.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Do your action here when user click No.. or just cancel dialog using follow..

dialog.cancel();
}
});
alertDialog.show();
}

As you can see Dialog is not so difficult, but need to identify exaclty which Builder you are gonna use.

YourActivity.this - means the activity where you create the dialog

You can also see available options of what you can implement inside dialog.. like 3 buttons.

Start typing alertDialog. finish with the dot and in Eclipse there will be new pop-up window and you can add some more

Also dont forget alertDialog.show(); at the end, otherwise Dialog wont shows​

HTC ListView and HtcListActivity. ​

There are two ways of implementing Htc List view. You can use Simple Activity, Fragment or just easy use HtcListActivity extension.

For full htc style you need to use Main List layout, and Details layout + List adapter.

Example using Activity

public class AboutActivity extends Activity {
[COLOR="Red"]HtcListView lv1;[/COLOR]

[MENTION=439709]override[/MENTION]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_activity);

ArrayList<AboutDetails> image_details = GetSearchResults();

[COLOR="red"]final HtcListView lv1 = (HtcListView) findViewById(R.id.about_list);[/COLOR]
[MENTION=1299008]supp[/MENTION]ressWarnings("unused")
lv1.setAdapter(new AboutListBaseAdapter(this, image_details));
lv1.setOnItemClickListener(new HtcAdapterView.OnItemClickListener() {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
[MENTION=439709]override[/MENTION]
public void onItemClick(HtcAdapterView<?> a, View v, int position, long id) {
vibrator.vibrate(50);
Object o = lv1.getItemAtPosition(position);
final AboutDetails obj_itemDetails = (AboutDetails)o;
}
});
}

private ArrayList<AboutDetails> GetSearchResults(){
ArrayList<AboutDetails> results = new ArrayList<AboutDetails>();

AboutDetails item_details = new AboutDetails();
item_details.setName(R.string.mikrosmile);
item_details.setItemDescription(R.string.mikrosmile_info);
item_details.setImageNumber(1);
results.add(item_details);

return results;
}
}

AboutDetails

public class AboutDetails {

public int getName() {
return name;
}
public void setName(int name) {
this.name = name;
}
public int getItemDescription() {
return itemDescription;
}
public void setItemDescription(int itemDescription) {
this.itemDescription = itemDescription;
}

public int getImageNumber() {
return imageNumber;
}
public void setImageNumber(int imageNumber) {
this.imageNumber = imageNumber;
}

private int name ;
private int itemDescription;
private int imageNumber;

}

AboutListBaseAdapter

public class AboutListBaseAdapter extends BaseAdapter {
private static ArrayList<AboutDetails> aboutDetailsrrayList;

private Integer[] imgid = {
R.drawable.mikrosmile,
};

private LayoutInflater l_Inflater;

public AboutListBaseAdapter(Context context, ArrayList<AboutDetails> results) {
aboutDetailsrrayList = results;
l_Inflater = LayoutInflater.from(context);
}

public int getCount() {
return aboutDetailsrrayList.size();
}

public Object getItem(int position) {
return aboutDetailsrrayList.get(position);
}

public long getItemId(int position) {
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.about_htc_details, null);
holder = new ViewHolder();
holder.txt_itemName = ([COLOR="red"]HtcListItem2LineText[/COLOR]) convertView.findViewById(R.id.list_item);
holder.itemImage = ([COLOR="red"]HtcListItemTileImage[/COLOR]) convertView.findViewById(R.id.list_item_img);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.txt_itemName.setPrimaryText(aboutDetailsrrayList.get(position).getName());
holder.txt_itemName.setSecondaryTextSingleLine(false);
holder.txt_itemName.setSecondaryText(aboutDetailsrrayList.get(position).getItemDescription());
holder.itemImage.setTileImageResource(imgid[aboutDetailsrrayList.get(position).getImageNumber() - 1]);

return convertView;
}

static class ViewHolder {
[COLOR="red"]HtcListItem2LineText txt_itemName;
HtcListItemTileImage itemImage;[/COLOR]
}
}

Layout - about_activity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_white">

<[COLOR="red"]com.htc.widget.HtcListView[/COLOR]
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/about_list"
android:background="@drawable/common_app_bkg"
/>
</LinearLayout>

Layout - about_htc_details

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<[COLOR="red"]com.htc.widget.HtcListItemSeparator [/COLOR]
android:id="@+id/Lseparator"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
[COLOR="red"]<com.htc.widget.HtcListItem
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.htc.widget.HtcListItemTileImage
android:id="@+id/list_item_img" />
<com.htc.widget.HtcListItem2LineText
android:id="@+id/list_item" />
</com.htc.widget.HtcListItem>[/COLOR]
</LinearLayout>

HTC ListView Example by xcesco89