0

此方法用于项目中,它应该在列表中显示项目的所有布局,当您单击其中一个时,它会显示它的按钮,当您单击其中一个按钮时,它会显示所有可绘制对象res,然后是我需要您帮助的部分:当您单击其中一个可绘制对象时,它必须显示您选择的布局以及您选择的按钮的新背景(您点击的可绘制对象)

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();

                }


            }


        }


}
4

1 回答 1

0

我只需要使最终可变位置

listView1.setOnItemClickListener(new OnItemClickListener(){

                        @Override
                            public void onItemClick(AdapterView<?> arg0, View arg1,
                                    int arg2, long arg3) {

    **setContentView(layoutid[position]**

                                      }

                        });
于 2013-02-26T09:11:06.663 回答