۱۳۹۵/۰۵/۱۸, ۰۸:۲۷ ب.ظ
سلام برای ساخت لیست ویو طبق آموزش سایت کلید483
لیست ویو مورد نظر بسازین و برای رویداد کلیک باتن ها
کد زیر
به این صورت بنویسین
لیست ویو مورد نظر بسازین و برای رویداد کلیک باتن ها
کد زیر
کد:
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item, parent, false);
String stringName = "string_key_" + String.valueOf(position+1);
int string_res_ID = getResources().getIdentifier(stringName,"string",getPackageName());
String my_string = getResources().getString(string_res_ID);
TextView tv = (TextView) row.findViewById(R.id.textView1);
tv.setText(my_string);
String imageName = "key_" + String.valueOf(position+1);
int image_res_ID = getResources().getIdentifier(imageName,"drawable",getPackageName());
ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
iv.setImageResource(image_res_ID);
return row;
}
}
به این صورت بنویسین
کد:
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item, parent, false);
String stringName = "string_key_" + String.valueOf(position+1);
int string_res_ID = getResources().getIdentifier(stringName,"string",getPackageName());
String my_string = getResources().getString(string_res_ID);
TextView tv = (TextView) row.findViewById(R.id.textView1);
tv.setText(my_string);
String imageName = "key_" + String.valueOf(position+1);
int image_res_ID = getResources().getIdentifier(imageName,"drawable",getPackageName());
ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
iv.setImageResource(image_res_ID);
///////////////////////کد مربوط به رویداد کلیک باتن با id=btn1
Button bn1=(Button) row.findViewById(R.id.btn1);
bn1.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
if (position==0)
{کد مورد نظر در صورتی روی باتن سطر اول در لیست ویو کلیک شده باشد}
if (position==1)
{کد مورد نظر در صورتی روی باتن سطر دوم در لیست ویو کلیک شده باشد}
if (position==2)
{کد مورد نظر در صورتی روی باتن سطر سوم در لیست ویو کلیک شده باشد}
}
}
);
////////////////////////////////////
return row;
}
}