第一项活动:
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;
}
}
答案 0 :(得分:0)
从一项活动转为另一项活动。查看intents 基本上就是这样:
Intent intent = new Intent(getContext(), ActivityToBeStarted.class);
intent.putExtra("messages", result);
startActivity(intent);
在activity 2'方法中,您可以使用oncreate方法开始:
String[] myStringArray = getIntent().getStringArrayExtra("messages");