انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
استقاده از چند دکمه (Button) در لیست ویو (ListView) (برنامه نویسی اندروید)

استقاده از چند دکمه (Button) در لیست ویو (ListView) (برنامه نویسی اندروید)

#6
سلام برای ساخت لیست ویو طبق آموزش سایت کلید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;
               }
             
             
       }
پاسخ
 سپاس شده توسط BahmanSE


پیام‌های این موضوع
RE: استقاده از چند دکمه در لیست ویو - توسط admin - ۱۳۹۵/۰۵/۱۴, ۰۱:۱۱ ب.ظ
RE: استقاده از چند دکمه (Button) در لیست ویو (ListView) (برنامه نویسی اندروید) - توسط aleas - ۱۳۹۵/۰۵/۱۸, ۰۸:۲۷ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان