0
我有一個按鈕,當我點擊它時,我想它顯示與圖像&文本(靜態文本)的列表視圖。我怎樣才能做到這一點?在Android中的圖像和文本的列表視圖
My code..
public class category extends ListActivity {
Button category;
TextView selection;
private static final String[] country = { "Iceland", "India", "Indonesia",
"Iran", "Iraq", "Ireland", "Israel", "Italy", "Laos", "Latvia",
"Lebanon", "Lesotho ", "Liberia", "Libya", "Lithuania",
"Luxembourg" };
private static final String[] curr = { "ISK", "INR", "IDR", "IRR", "IQD",
"EUR", "ILS", "EUR", "LAK", "LVL", "LBP", "LSL ", "LRD", "LYD",
"LTL ", "EUR"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
category=(Button)findViewById(R.id.category);
class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public EfficientAdapter(OnClickListener onClickListener) {
mInflater = LayoutInflater.from((Context) onClickListener);
}
public int getCount() {
return country.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text = (TextView) convertView
.findViewById(R.id.TextView01);
holder.text2 = (TextView) convertView
.findViewById(R.id.TextView02);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(curr[position]);
holder.text2.setText(country[position]);
return convertView;
}
class ViewHolder {
TextView text;
TextView text2;
}
}
category.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ListView l1 = (ListView) findViewById(R.id.ListView);
l1.setAdapter(new EfficientAdapter(this));
}
});
}
}
開始一個活動,它只包含一個button.onClick按鈕使用一個intent來調用這個活動。這是你想要的嗎? –
謝謝你的答覆。但我需要在同一頁面顯示列表視圖(圖片和文字),當我點擊按鈕。 – sanjay