2013-02-25 213 views
0

此方法用于项目中应该显示项目在列表中的所有布局,并且当您单击其中一个项目时,会向您显示其按钮,并且当您单击某个按钮时在这些按钮中,它将所有drawable放置在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

我需要只是为了使最终的可变位置

listView1.setOnItemClickListener(新OnItemClickListener(){

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

    **setContentView(layoutid[position]** 

             } 

         });