Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 显示名称';指定布局的按钮_Android_String_Adapter - Fatal编程技术网

Android 显示名称';指定布局的按钮

Android 显示名称';指定布局的按钮,android,string,adapter,Android,String,Adapter,我试图显示tab_s,但我唯一得到的是用LogCat显示的变量“s”,但当我尝试将此变量放入字符串[]时,它只显示一个黑屏,我如何将此变量放入字符串数组 private void allbuttons() { Class cls = R.drawable.class; fieldlist = cls.getDeclaredFields(); setContentView(layoutIds[position]); String[] ta

我试图显示tab_s,但我唯一得到的是用LogCat显示的变量“s”,但当我尝试将此变量放入字符串[]时,它只显示一个黑屏,我如何将此变量放入字符串数组

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);
private void allbuttons()
{Class cls=R.drawable.Class;
fieldlist=cls.getDeclaredFields();
setContentView(layoutIds[position]);
字符串[]制表符=null;
ListView ListView=(ListView)findViewById(R.id.listViewallbuttons);
allButtonsInLayout=getViewsFromViewGroup(findViewById(android.R.id.content),Button.class);
Toast.makeText(这个““+allButtonsInLayout.size(),Toast.LENGTH\u SHORT.show();

对于(int i=0;i我找到了一个解决方案,问题在于选项卡的大小,所以想法是在选项卡的大小变小时创建另一个数组,并将选项卡复制到另一个数组temp中,最终选项卡将包含我想要的任何内容

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();
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);
//字符串tabname=allButtonsInLayout.get(位置).getResources().getResourceEntryName(位置);
Toast.makeText(这个““+allButtonsInLayout.size(),Toast.LENGTH\u SHORT.show();
int size=allButtonsInLayout.size();
String[]tab_s=新字符串[大小];
int k=0;
字符串s;
//位图bm=null;
//SQLiteAdapter mySQLiteAdapter=新的SQLiteAdapter(getApplicationContext());
//mySQLiteAdapter.openToRead();
//bm=mySQLiteAdapter.queueAllphoto();
//mySQLiteAdapter.close();
//所有按钮布局。获取(i)。可后退(d);
cls=R.drawable.class;
fieldlist=cls.getDeclaredFields();
字符串fieldName=null;
for(java.lang.reflect.Field fld:fieldlist){
对于(int i=0;i