这个方法用在一个项目中,它应该在列表中显示项目的所有布局,当你点击其中一个时,它会显示它的按钮,当你点击其中一个按钮时,它会显示所有res中的drawable,然后是我需要你帮助的部分:当你克服其中一个drawable时,它必须显示你选择的布局,你选择的按钮是新的背景(你画的是可绘制的)
public void myclass{
Class<drawable> cls = R.drawable.class;
fieldlist = cls.getDeclaredFields();
setContentView(layoutIds[position]);
allButtonsInLayout = getViewsFromViewGroup(findViewById(android.R.id.content), Button.class);
//allButtonsInLayout = getViewsFromViewGroup(findViewById(android.R.id.content), Button.class);
//String tabname=allButtonsInLayout.get(position).getResources().getResourceEntryName(position);
Toast.makeText(this, "" + allButtonsInLayout.size(), Toast.LENGTH_SHORT).show();
int size=allButtonsInLayout.size();
String[] tab_s = new String [size];
cls = R.drawable.class;
fieldlist = cls.getDeclaredFields();
for (java.lang.reflect.Field fld : fieldlist) {
int i=0;
for( i=0;i<allButtonsInLayout.size();i++){
try {
setContentView(R.layout.listallbuttons);
final ListView listView1 = (ListView) findViewById(R.id.listViewallbuttons);
drawableId = fld .getInt(null);
String s = fld.getName();
Log.v("tagllll", "msg" + s);
if((k<=i)) {
tab_s[k++]=s;
}
else{
size++;
String[]temp=new String[size];
for (int f=0;f<tab_s.length;f++){
temp[f]=tab_s[f];
}
tab_s=temp;
tab_s[k++]=s;
}
for (int k1=0;k1<tab_s.length;k1++){
//int j=allButtonsInLayout.size();
if (k1%allButtonsInLayout.size()!=0){
tab_s[k1]="null";
}
}
ArrayList<String> wordList = convertStringArrayToArraylist(tab_s);
int jk=0;
while ( jk<size){
wordList.remove("null");
jk++;
}
drawableId--;
allButtonsInLayout.get(i).setBackgroundResource(drawableId);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,wordList);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
**that's the part where i am lost i need to show the chosen layout with the clicked button with a new background(the one i choosed**
}
});
}
catch(Exception e){
e.getMessage();
}
}
}
}
答案 0 :(得分:0)
我只需要最终确定变量位置 listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
**setContentView(layoutid[position]**
}
});