2013-02-14 5 views
0

Я пытаюсь отобразить tab_s, но единственное, что у меня есть, это просто переменная «s», отображаемая с помощью LogCat, но когда я пытаюсь поместить эту переменную в String [], это просто показать мне черный экран, как я могу поставить эту переменную в строковый массивотображать кнопки названия определенного макета

private void allbuttons() 
{  Class cls = R.drawable.class; 
     fieldlist = cls.getDeclaredFields(); 
     setContentView(layoutIds[position]); 
     String[] tab_s = null; 
     ListView listView = (ListView) findViewById(R.id.listViewallbuttons); 

     allButtonsInLayout = getViewsFromViewGroup(findViewById(android.R.id.content), Button.class); 

     Toast.makeText(this, "" + allButtonsInLayout.size(), Toast.LENGTH_SHORT).show(); 


     for( int i=0;i<allButtonsInLayout.size();i++){ 






      cls = R.drawable.class; 
      fieldlist = cls.getDeclaredFields(); 

      String fieldName = null ; 

      for (java.lang.reflect.Field fld1 : fieldlist) { 



       try { 
        setContentView(R.layout.listallbuttons); 
        ListView listView1 = (ListView) findViewById(R.id.listViewallbuttons); 



        drawableId = fld1 .getInt(null); 
        String s=getResources().getResourceEntryName(drawableId); 
        Log.v("tagllll", "msg" + s); 

        tab_s[i]=s; 



        Log.v("tagtab_s", "msg" + tab_s[i]); 



        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
          android.R.layout.simple_list_item_1, android.R.id.text1,tab_s); 
        listView1.setAdapter(adapter); 

ответ

0

я нашел решение проблемы был размером tab_s поэтому идея заключается в том, чтобы создать еще один массив, когда размер tab_s является небольшой и скопируйте tab_s в другой массив temp, и в итоге tab_s будет содержать все, что я хочу!

Class cls = R.drawable.class; 
fieldlist = cls.getDeclaredFields(); 
setContentView(layoutIds[position]); 
java.lang.reflect.Field fld1; 
ListView listView = (ListView) findViewById(R.id.listViewallbuttons); 

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]; 
int k = 0; 
String s; 

    // Bitmap bm = null; 
    // SQLiteAdapter mySQLiteAdapter =new SQLiteAdapter(getApplicationContext()); 
    //mySQLiteAdapter.openToRead(); 
    // bm=mySQLiteAdapter.queueAllphoto(); 
    //mySQLiteAdapter.close(); 
    //allButtonsInLayout.get(i).setBackgroundDrawable(d); 

    cls = R.drawable.class; 
    fieldlist = cls.getDeclaredFields(); 

    String fieldName = null ; 

    for (java.lang.reflect.Field fld : fieldlist) { 

     for( int i=0;i<allButtonsInLayout.size();i++){ 

     try { 


      setContentView(R.layout.listallbuttons); 
      ListView listView1 = (ListView) findViewById(R.id.listViewallbuttons); 



      drawableId = fld .getInt(null); 

      s=getResources().getResourceEntryName(drawableId); 

      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; 
       /*for (int f=0;f<tab_s.length;f++){ 
        if (tab_s[f]==tab_s[f--]){ 
         tab_s[f]=null; 
        } 
       }*/ 
       if(tab_s[k]!=s) 
       tab_s[k++]=s; 

      } 



      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
         android.R.layout.simple_list_item_1, android.R.id.text1,tab_s); 

       listView1.setAdapter(adapter); 





      //MyAdapter mine=new MyAdapter(getBaseContext(),s); 

      /*Builder builder = new AlertDialog.Builder(this); 
      builder.setTitle("application_name"); 
      builder .setMessage("Vous avez cliqué sur : " + s); 
      builder.show();*/ 






      //Log.v("tagtab_s", "msg" + tab_s[i]); 

      //layoutButtons[k]=fieldName; 


      drawableId--; 
      allButtonsInLayout.get(i).setBackgroundResource(drawableId); 
      //int k=getResources().getInteger(drawableId); 





     } 
     catch(Exception e){ 

      e.getMessage(); 
      Toast.makeText(DvpList2.this, 
        "plus d'images", Toast.LENGTH_SHORT).show(); 
     } 
     allButtonsInLayout.get(i).setOnClickListener(new OnClickListener(){ 

       @Override 
       public void onClick(View v) { 
        try{ 
         drawableId--; 
         //allButtonsInLayout.get(i).setBackgroundResource(drawableId); 
        } 
        catch(Exception e){ 

         e.getMessage(); 
         Toast.makeText(DvpList2.this, 
           "plus d'images", Toast.LENGTH_SHORT).show(); 
        } 
       } 








      }); 




     // do whatever with the drawable 

    } 


} 





    //Bitmap bmp = BitmapFactory.decodeByteArray(content,0,content.length); 

    //image = new BitmapDrawable(BitmapFactory.decodeByteArray(content, 0, content.length)); 


    Toast.makeText(DvpList2.this, 
      "ImageButton is clicked!", Toast.LENGTH_SHORT).show(); 
Смежные вопросы