第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

android中使用arrayadapter類(lèi)的自定義列表視圖

android中使用arrayadapter類(lèi)的自定義列表視圖

POPMUISE 2020-02-03 13:07:44
當(dāng)我單擊列表行項(xiàng)目然后在行imageview中顯示圖像時(shí),如何使用像Android中的iphone這樣的刻度線(xiàn)選擇行項(xiàng)目?if(getItem(position)!=null){img.setvisibilty(View.Visible);}        else{System.out.println("imagenull");}我使用此功能,但圖像僅顯示在最后一行。請(qǐng)幫助我如何使用刻度線(xiàn)圖像選擇項(xiàng)目。public class DistanceArrayAdapter extends ArrayAdapter<Constant>{public static String category,state,miles;public ImageView img;private Context context;private int current = -1;ArrayList<Constant> dataObject;public DistanceArrayAdapter(Context context, int textViewResourceId,ArrayList<Constant> dataObject) {super(context, textViewResourceId, dataObject);this.context=context;}@Overridepublic View getView(final int position, View convertView, ViewGroup parent) {View rowView=convertView;if(rowView==null){LayoutInflater inflater = (LayoutInflater) context            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);rowView = inflater.inflate(R.layout.category_row, parent, false);}    //TextView textView = (TextView) rowView.findViewById(R.id.text1);TextView textView1 = (TextView) rowView.findViewById(R.id.text2);    //textView.setText(""+getItem(position).id);textView1.setText(""+getItem(position).caption);img=(ImageView)rowView.findViewById(R.id.img);img.setVisibility(View.GONE);if(position%2==1){rowView.setBackgroundResource(R.color.even_list);}else    {        rowView.setBackgroundResource(R.color.odd_list);    }rowView.setOnClickListener(new OnClickListener(){        @Override        public void onClick(View v) {            if(img.getVisibility()==View.GONE)            {                img.setVisibility(View.VISIBLE);                System.out.println("1");            }if(img.getVisibility()==View.VISIBLE){img.setVisibility(View.GONE);System.out.println("12");}miles=getItem(position).caption;System.out.println("miles"+miles);}});return rowView;}}
查看完整描述

3 回答

?
桃花長(zhǎng)相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊

在ListView上設(shè)置選擇模式


    //if using ListActivity or ListFragment

 getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);


    //or


     myListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);


    //myListView is reference to your ListView


查看完整回答
反對(duì) 回復(fù) 2020-02-03
?
千萬(wàn)里不及你

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊

我使用數(shù)組適配器為具有復(fù)選框的列表創(chuàng)建了一個(gè)示例示例。


在Android中使用ArrayAdatpter使用CheckBox實(shí)現(xiàn)ListView


您也可以找到示例代碼。


這將被輸出


這是我的代碼片段


我有一個(gè)具有列表視圖的活動(dòng)


public class MainActivity extends Activity {


 private ListView mainListView = null;

 private Planet[] planets = null;

 private ArrayAdapter<Planet> listAdapter = null;


 @Override

 public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);


  mainListView = (ListView) findViewById(R.id.mainListView);


  // When item is tapped, toggle checked properties of CheckBox and

  // Planet.

  mainListView

  .setOnItemClickListener(new AdapterView.OnItemClickListener() {

   @Override

   public void onItemClick(AdapterView<?> parent, View item,

    int position, long id) {

   Planet planet = listAdapter.getItem(position);

   planet.toggleChecked();

   PlanetViewHolder viewHolder = (PlanetViewHolder) item

    .getTag();

   viewHolder.getCheckBox().setChecked(planet.isChecked());

   }

  });


  // Create and populate planets.

  planets = (Planet[]) getLastNonConfigurationInstance();

  if (planets == null) {

   planets = new Planet[] { new Planet("Mercury"),

     new Planet("Venus"), new Planet("Earth"),

     new Planet("Mars"), new Planet("Jupiter"),

     new Planet("Saturn"), new Planet("Uranus"),

     new Planet("Neptune"), new Planet("Ceres"),

     new Planet("Pluto"), new Planet("Haumea"),

     new Planet("Makemake"), new Planet("Eris") };

  }

  ArrayList<Planet> planetList = new ArrayList<Planet>();

  planetList.addAll(Arrays.asList(planets));


  // Set our custom array adapter as the ListView's adapter.

  listAdapter = new PlanetArrayAdapter(this, planetList);

  mainListView.setAdapter(listAdapter);

 }


 public Object onRetainNonConfigurationInstance() {

  return planets;

 }

}

這是我正在處理復(fù)選框內(nèi)容的“自定義陣列適配器”


public class PlanetArrayAdapter extends ArrayAdapter<Planet> {


 private LayoutInflater inflater;


 public PlanetArrayAdapter(Context context, List<Planet> planetList) {

 super(context, R.layout.simplerow, R.id.rowTextView, planetList);

 //Cache the LayoutInflate to avoid asking for a new one each time.

  inflater = LayoutInflater.from(context);

 }


 @Override

 public View getView(int position, View convertView, ViewGroup parent){

  Planet planet = (Planet) this.getItem(position);

  CheckBox checkBox;

  TextView textView;


  // Create a new row view

  if (convertView == null) {

  convertView = inflater.inflate(R.layout.simplerow, null);


  textView = (TextView) convertView.findViewById(R.id.rowTextView);

  checkBox = (CheckBox) convertView.findViewById(R.id.CheckBox01);


  convertView.setTag(new PlanetViewHolder(textView, checkBox));


  // If CheckBox is toggled, update the planet it is tagged with.

  checkBox.setOnClickListener(new View.OnClickListener() {

   public void onClick(View v) {

    CheckBox cb = (CheckBox) v;

    Planet planet = (Planet) cb.getTag();

    planet.setChecked(cb.isChecked());

   }

  });

  }

  // Re-use existing row view

  else {


  PlanetViewHolder viewHolder = (PlanetViewHolder) convertView

     .getTag();

   checkBox = viewHolder.getCheckBox();

   textView = viewHolder.getTextView();

  }


  checkBox.setTag(planet);


  // Display planet data

  checkBox.setChecked(planet.isChecked());

  textView.setText(planet.getName());


  return convertView;

 }


}

請(qǐng)!讓我知道您是否有任何麻煩。


查看完整回答
反對(duì) 回復(fù) 2020-02-03
  • 3 回答
  • 0 關(guān)注
  • 1020 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)