ich this Tutorial verwenden und implementiert erfolgreich einen Code Daten in einer Aktivität (in Form von Dialog), die ListActivityzeigen zwei Schaltflächen am Boden in einem ListActivity
erstreckt Noch zu zeigen, ich bin immer Daten in ein unten Format unter Verwendung eines Dialog Thema
Nun würde ich gerne wissen, wie kann ich hinzufügen, zwei Tasten an der Unterseite?
Genau wie wir sehen in der Regel in Alertdialog (e): OK und Abbrechen
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;
}
}
Dies wird diese beiden Schaltflächen in jedem Listenelement hinzufügen ... – Sophie
Nein wird es nicht, wenn "unterhalb" der ListView platziert. – mwieczorek
fügen Sie das unter Ihrem Listenansicht nicht Ihrem Listenelement hinzu xml –