【发布时间】:2014-01-09 11:48:50
【问题描述】:
我在一个活动中有 7 个图像,当我单击任何图像时,它会更改其背景颜色以向用户显示效果,现在我想要做的是当用户单击任何图像并按下我想要的提交按钮时该图像到下一个活动并在图像视图中显示。
所以在上述活动中,我有周一、周二等图片......
所以在我的下一个活动中,我有一个带有一个复选框、图像视图和文本视图的自定义列表视图,所以基本上我想在列表视图的图像视图中显示该特定图像,那么我该如何实现这一点。
下面是我的代码。
notappl.setOnClickListener(new ImageView.OnClickListener() {
public void onClick(View v) {
notappl.setImageResource(R.drawable.na_press);
computer.setImageResource(R.drawable.computer);
piggy.setImageResource(R.drawable.piggy_bank);
book.setImageResource(R.drawable.book);
maths.setImageResource(R.drawable.mathsicon);
dna.setImageResource(R.drawable.dnaicon);
brain.setImageResource(R.drawable.brain_icon);
}
});
computer.setOnClickListener(new ImageView.OnClickListener() {
public void onClick(View v) {
notappl.setImageResource(R.drawable.na);
computer.setImageResource(R.drawable.computer_press);
piggy.setImageResource(R.drawable.piggy_bank);
book.setImageResource(R.drawable.book);
maths.setImageResource(R.drawable.mathsicon);
dna.setImageResource(R.drawable.dnaicon);
brain.setImageResource(R.drawable.brain_icon);
}
});
所有图片都以此类推
MyListModel.java
package iqualtech.skirr;
public class List_ClassModel {
private String class_name;
private int class_ID;
public List_ClassModel() {
}
public List_ClassModel(String class_name) {
this.class_name = class_name;
}
public String getClassName() {
return class_name;
}
public void setClassName(String class_name) {
this.class_name = class_name;
}
public int getClass_ID() {
return class_ID;
}
public void setClass_ID(int class_ID) {
this.class_ID = class_ID;
}
}
CustomAdapter.java
public class Custom_ClassAdapter extends BaseAdapter {
LayoutInflater inflater;
Context context;
List<List_ClassModel> rowItems;
public Custom_ClassAdapter(Context context, List<List_ClassModel> rowItems) {
inflater = LayoutInflater.from(context);
this.context = context;
this.rowItems = rowItems;
}
private class ViewHolder {
ImageView mImageView;
TextView mTextView;
CheckBox mCheckBox;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_class, null);
holder = new ViewHolder();
holder.mImageView = (ImageView) convertView
.findViewById(R.id.classImage);
holder.mTextView = (TextView) convertView
.findViewById(R.id.classname);
holder.mCheckBox = (CheckBox) convertView
.findViewById(R.id.checkBox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.mCheckBox.setTag(position);
holder.mCheckBox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
Code.classDel = (Integer) buttonView.getTag();
Log.d("sdfdsf", "sdfsdf");
}
});
List_ClassModel rowItem = (List_ClassModel) getItem(position);
holder.mTextView.setText(rowItem.getClassName());
return convertView;
}
@Override
public int getCount() {
return rowItems.size();
}
@Override
public Object getItem(int position) {
return rowItems.get(position);
}
@Override
public long getItemId(int position) {
return rowItems.indexOf(getItem(position));
}
public void clear() {
}
}
CustomClass.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/assignmentheader" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="@+id/classname"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="@+id/classImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp" />
</LinearLayout>
【问题讨论】:
-
holder.mImageView .setImageResource(rowItem .getClass_ID()) -
@Raghunandan,感谢您的快速回复,但我应该在我的图像视图点击事件中传递什么。
-
您可以使用意图并将 id 传递给下一个活动以在那里显示图像
-
我的所有图像点击事件,如 notappl 或计算机等,或任何其他更改,因为我刚刚创建了用于更改图像背景颜色的代码。那么它将如何使用您提供的代码拍摄该图像。
-
我真的不明白你的评论。可以更具体一点,解释清楚
标签: android android-listview android-activity android-imageview