如何在 imageview 上设置 onClick 以在另一个 layout.xml 上设置 backgroundresource 即使我关闭应用程序然后再次打开它,另一个 layout.xml 上的 backgroundresource 是我当时点击的 imageview 吗?
这是我的代码,内容是我想成为背景源的图像
public class Main2Activity extends BaseAdapter {
private List<Item> items = new ArrayList<Item>();
private LayoutInflater inflater;
public Main2Activity(Context context) {
inflater = LayoutInflater.from(context);
items.add(new Item("Cindvia", R.drawable.cindvia));
items.add(new Item("Harugon", R.drawable.harugon));
items.add(new Item("Melodist", R.drawable.melodist));
items.add(new Item("Nabilaholic", R.drawable.nabilaholic));
items.add(new Item("Nat", R.drawable.nat));
items.add(new Item("Rona", R.drawable.rona));
items.add(new Item("Shanju", R.drawable.shanju));
items.add(new Item("Shinta", R.drawable.shinta_n));
items.add(new Item("Ve", R.drawable.ve));
items.add(new Item("Vienny", R.drawable.vienny));
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int i) {
return items.get(i);
}
@Override
public long getItemId(int i) {
return items.get(i).drawableId;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v = view;
ImageView picture;
TextView name;
if(v == null) {
v = inflater.inflate(R.layout.activity_main, viewGroup, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
v.setTag(R.id.text, v.findViewById(R.id.text));
}
picture = (ImageView)v.getTag(R.id.picture);
name = (TextView)v.getTag(R.id.text);
Item item = (Item)getItem(i);
picture.setImageResource(item.drawableId);
name.setText(item.name);
return v;
}
private class Item {
final String name;
final int drawableId;
Item(String name, int drawableId) {
this.name = name;
this.drawableId = drawableId;
}
}
}
这是我想要更改背景的 .XML 代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity"
android:background="@drawable/nat" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:shadowColor="#ffb4b4"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="3"
android:text="@string/eee_dd_mm_yyyy"
android:textColor="#ffffff"
android:textSize="17sp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:shadowColor="#ffb4b4"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="4"
android:text="@string/hh_mm_ss"
android:textColor="#ffffff"
android:textSize="37sp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="17dp"
android:layout_marginRight="17dp"
android:src="@drawable/info"
android:contentDescription="@string/todo"/>
它是下载我所有工作区的链接,我的意思是我正在使用的代码,
如果要下载,请单击文件并下载
https://drive.google.com/file/d/0B7NPhjxHR4zbT2NaUDBRNnU4cWc/edit?usp=sharing