0
怎麼樣?我有select1和select2靜態string []變量,並聲明瞭myval,myvals兩個全局變量。 如果我從列表項目中選擇項目,那麼項目可見並且下一個活動自定義listView;如何從一個Activity自定義listview到另一個activity自定義listView?
第一項活動:
l1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//When clicked, show a toast with the TextView text
Toast.makeText(HomeActivity.this, "SELECTED :: " + "item "+ select1[position] + " " + "price"+ select2[position],
Toast.LENGTH_SHORT).show();
String s1=select1[position];
GlobalClass.myval.add(s1);
String s2=select2[position];
GlobalClass.myvals.add(s2);
}
高效適配器:
public static class EfficientAdapter extends BaseAdapter{
private LayoutInflater mInflater;
public EfficientAdapter(Context context){
mInflater=LayoutInflater.from(context);
}
public int getCount() {
return select1.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.list_row,null);
holder=new ViewHolder();
holder.Text1=(TextView) convertView.findViewById(R.id.textView1);
holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else{
holder=(ViewHolder) convertView.getTag();
}
holder.Text1.setText(select1[position]);
holder.Text2.setText(select2[position]);
return convertView;
}
static class ViewHolder{
TextView Text1;
TextView Text2;
}
下一個活動:
private static class EfficientAdapter extends BaseAdapter{
private LayoutInflater mInflater;
public EfficientAdapter(Context context){
mInflater=LayoutInflater.from(context);
// implementation of EfficientAdapter
}
public int getCount() {
return HomeActivity.select1.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.list_ticket, null);
holder=new ViewHolder();
//holder.Text1=(TextView) convertView.findViewById(R.id.textView1);
holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
holder.Text3=(TextView) convertView.findViewById(R.id.textView3);
convertView.setTag(holder);
}
else{
holder=(ViewHolder)convertView.getTag();
}
holder.Text2.setTag(GlobalClass.myval);
holder.Text3.setTag(GlobalClass.myvals);
return convertView;
}
static class ViewHolder{
TextView Text1;
TextView Text2;
TextView Text3;
}
}
不需要你的適配器代碼,只需要知道哪些「之類的項目/價值類型「。以及你如何開始其他活動。也許如果它是多選列表視圖? – 2012-08-02 07:16:19
String []值,轉到另一個用於按鈕的活動點擊 – USER5762 2012-08-02 07:18:03
它應該在那附近:)記得接受答案 – 2012-08-02 13:07:05