I am using this tutorial and successfully implemented a code to show Data in an Activity (in form of Dialog) which extends ListActivity
Still, I am getting Data in a below format by using a Dialog theme
Now, I would like to know, How Can I add two buttons at bottom ?
Just like We usually see in AlertDialog(s) : OK and CANCEL
CountrycodeActivity.java:
public class CountrycodeActivity extends ListActivity {
public static String RESULT_CONTRYCODE = "countrycode";
public String[] countrynames, countrycodes;
private TypedArray imgs;
private List<Country> countryList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
populateCountryList();
ArrayAdapter<Country> adapter = new CountryListArrayAdapter(this, countryList);
setListAdapter(adapter);
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Country c = countryList.get(position);
Intent returnIntent = new Intent();
returnIntent.putExtra(RESULT_CONTRYCODE, c.getCode());
setResult(RESULT_OK, returnIntent);
imgs.recycle(); //recycle images
finish();
}
});
}
private void populateCountryList() {
countryList = new ArrayList<Country>();
countrynames = getResources().getStringArray(R.array.country_names);
countrycodes = getResources().getStringArray(R.array.country_codes);
imgs = getResources().obtainTypedArray(R.array.country_flags);
for(int i = 0; i < countrycodes.length; i++){
countryList.add(new Country(countrynames[i], countrycodes[i], imgs.getDrawable(i)));
}
}
public class Country {
private String name;
private String code;
private Drawable flag;
public Country(String name, String code, Drawable flag){
this.name = name;
this.code = code;
this.flag = flag;
}
public String getName() {
return name;
}
public Drawable getFlag() {
return flag;
}
public String getCode() {
return code;
}
}
}
CountryListArrayAdapter.java:
public class CountryListArrayAdapter extends ArrayAdapter<CountrycodeActivity.Country> {
private final List<CountrycodeActivity.Country> list;
private final Activity context;
static class ViewHolder {
protected TextView name;
protected ImageView flag;
}
public CountryListArrayAdapter(Activity context, List<CountrycodeActivity.Country> list) {
super(context, R.layout.activity_countrycode_row, list);
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.activity_countrycode_row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.name = (TextView) view.findViewById(R.id.name);
viewHolder.flag = (ImageView) view.findViewById(R.id.flag);
view.setTag(viewHolder);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.name.setText(list.get(position).getName());
holder.flag.setImageDrawable(list.get(position).getFlag());
return view;
}
}

Add this two lines in your listview
and below your listview add this linear layout