我想在列表视图的每一行的右侧设置 3 个图标。我正在制作购物应用程序,当用户在列表视图中选择任何产品时,我想在其中选择任何产品,这样他/她就可以以 3 种方式查看产品,就像用户选择图标一样1 所以用户可以在网格视图中看到产品,如果用户选择图标 2 所以用户可以在图像切换器中看到产品,在图标 3 上用户可以在列表视图中看到产品实际上我希望用户在 3 视图中看到产品。当点击图标时下一个活动打开就像用户选择网格视图的图标一样,所以下一个活动将打开网格视图。这是我的代码
public class ListViewSupplementActivityActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.listlayout);
ListView view = (ListView) findViewById(R.id.list);
view.setAdapter(new CustomImageListAapter(this));
view.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
if(position ==0)
{
Intent ii = new Intent(ListViewSupplementActivityActivity.this,SingleListItem.class);
ii.putExtra("operation", position);
startActivity(ii);
}
if(position ==1){
Intent in = new Intent(ListViewSupplementActivityActivity.this,Test.class);
in.putExtra("operation", position);
startActivity(in);
}
if(position == 5){
Intent in2= new Intent(ListViewSupplementActivityActivity.this,FullImageActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("operation", position);
in2.putExtras(bundle);
startActivity(buse); }
}
});
}
}
这是自定义适配器类:
public class CustomImageListAapter extends BaseAdapter {
private int[] images = {R.drawable.autumnwalk, R.drawable.bridge,R.drawable.butterfly,
R.drawable.cheetah, R.drawable.cloud, R.drawable.su, R.drawable.wi,
R.drawable.rocksculpture, R.drawable.skyatsunset, R.drawable.s,
R.drawable.smoke, R.drawable.tulips};
private String[] imageDesc = { "Autumn Walk", "Bridge",
"Butterfly", "Cheetah", "Cloud", "Highway", "Martini",
"Rock Sculpture", "Sky at Sunset", "Sliced Orange", "Smoke",
"Tulips"};
private Context ctx = null;
public CustomImageListAapter(Context context) {
this.ctx = context;
}
public int getCount() {
return images.length;
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView imgView = new ImageView(this.ctx);
imgView.setScaleType(ScaleType.FIT_CENTER);
imgView.setPadding(8, 8, 8, 8);
imgView.setImageResource(images[arg0]);
imgView.setAdjustViewBounds(Boolean.TRUE);
imgView.setContentDescription(imageDesc[arg0]);
imgView.setMaxHeight(200);
imgView.setMaxWidth(200);
TextView tv = new TextView(this.ctx);
tv.setText(imageDesc[arg0]);
tv.setMaxHeight(100);
tv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tv.setGravity(Gravity.CENTER);
LinearLayout layoutView = new LinearLayout(this.ctx);
layoutView.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(150, 150);
layoutView.addView(imgView, params1);
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
layoutView.addView(tv, params2);
return layoutView;}
}