Button listview中的选定项
在布局中,我单击一个按钮以显示res/drawable中所有可绘制内容的列表。当我单击其中一个按钮时,我必须显示相同的布局。我的问题是如何访问用户之前单击的按钮Button listview中的选定项,button,drawable,Button,Drawable,在布局中,我单击一个按钮以显示res/drawable中所有可绘制内容的列表。当我单击其中一个按钮时,我必须显示相同的布局。我的问题是如何访问用户之前单击的按钮 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { setContentView(layoutIds[position]); Button button=allButtonsInLayou
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
setContentView(layoutIds[position]);
Button button=allButtonsInLayout.get(arg2);
button.setBackgroundResource(R.drawable.images_sos);
}
但如果我把那行改成
Button button=allButtonsInLayout.get(arg2);
setContentView(R.layout.otherview);
//matable是一个包含所有可绘图项的表,它包含的id正好是它们的id
//然后我创建的按钮数量与drawable的id数量完全相同
对于(int k1=0;k1)如果您需要更多关于我的问题的解释,我在这里我成功地显示了一个所有布局的列表视图和另一个具有单击布局的所有按钮的列表视图,我还可以以res显示所有可绘制内容,之后我应该显示相同的布局,但有一个新的背景(我单击的可绘制内容)在我之前单击的按钮上,如果您需要更多代码来理解我的问题,我可以给您提供,请添加所用语言的标记。
Button button=allButtonsInLayout.get(arg2);
setContentView(R.layout.otherview);
//matable is a table of all drawable it contains exactly thier id
//then i creat exactly the same number of buttons than the number of drawable's id
for (int k1=0;k1<matable.length;k1++){
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Button btn = new Button(getBaseContext());
btn.setId(k1);
final int id_ = btn.getId();
LinearLayout linear = (LinearLayout) findViewById(R.id.linearscroll);
linear.addView(btn, params);
final Button btn1 = ((Button) findViewById(id_));
try{
btn1.setBackgroundResource(matable[k1]);
ht = new Hashtable<Integer, Integer>();
ht.put(id_, matable[k1]);
ht.put(3, 145);
}catch(Exception e){
e.printStackTrace();
}
btn1.setId(k1);
btn1.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick( View view) {
setContentView(lemien);
int test=v.getId();
test=test+3;
//and it 's exactly here where i make the comparaison
if(btn1.getId()==view.getId()){
int cpt=0;
tabIdButton[cpt]=view.getId();
d=btn1.getBackground();
BitmapDrawable bmd = (BitmapDrawable) d;
Bitmap bm = bmd.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
try{
Button btn3 = ((Button) findViewById(v.getId()));
btn3.setBackgroundDrawable(d);
SQLiteAdapter mySQLiteAdapter =new SQLiteAdapter(getBaseContext());
mySQLiteAdapter.openToWrite();
mySQLiteAdapter.insertintdrawableid(btn3.getId());
mySQLiteAdapter.insertphotobouton(bitmapdata);
mySQLiteAdapter.close();
Log.v("btn2", "btn2 j'ai chnagé");
}catch(Exception e){
e.printStackTrace();
}
}