如何从另一个活动加载自定义列表视图中的图像

时间:2014-01-09 11:48:51

标签: android android-listview android-activity android-imageview

我在一个活动中有7个图像,当我点击任何图像时它会改变它的背景颜色以向用户显示效果,现在我想要做的是当用户点击任何图像并按下提交按钮我想要获得该图像到下一个活动并在图像视图中显示。

enter image description here

所以在上面的活动中我有像Mon,Tue等图像......

所以在我的下一个活动中,我有自定义列表视图,其中包含一个复选框,图像视图和文本视图,所以基本上我想在列表视图的图像视图中显示该特定图像,以便我如何实现这一点。

以下是我的代码。

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>

1 个答案:

答案 0 :(得分:0)

只需获取图片网址..

将其保存为字符串..

然后点击传递给另一个使用bundle的活动..

在其他活动中获取该网址并按照您的意愿行事。

<强>更新

点击按钮会将您的值传递给..

Intent intent = new Intent (MainActivity.this, NewActivity.class);
            your_image.putExtra("valueq", R.drawable.app_icon);
            startActivities(intent);

当你需要在新班级中重温那个......

imag_link = getIntent().getIntExtra("valueq", value);

确保传递一个int值,这样你就需要在新的类中获取它。

就是这样。