1

want to change integer array to string array for viewing images in gridview.Arrayadapter only supports string arrays for animation in android `

int[] resource={R.drawable.chinanight,R.drawable.huhu,R.drawable.jkjkj,R.drawable.kkk};
String aa=Arrays.toString(resource);
String[] ay=aa.split(aa);

GridView grid;


protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid_view);

    grid=(GridView)findViewById(R.id.gridView1);


    ArrayAdapter ar=new ArrayAdapter(this,android.R.layout.simple_list_item_1,ay);
    grid.setAdapter(ar);

    Animation asd=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.right);
    grid.startAnimation(asd);
}` 

Pls Help

1 Answer 1

1

The point of an adapter is to link a set of data to a set of views (which are created by the AdapterView i.e. ListView) - you don't give it an array of views to use.Create an Arraylist to refrence your drawables.

    ArrayList<Pair<String, Integer>> array = new ArrayList<Pair<String, Integer>>();
    array.add(Pair.create("Drawable1",R.drawable.chinanight));
 array.add(Pair.create("Drawable2", R.drawable.dfg));
 array.add(Pair.create("Drawable3", R.drawable.sf));
 array.add(Pair.create("Drawable4", R.drawable.sdf));


 ArrayAdapter ar=new ArrayAdapter(this,android.R.layout.simple_list_item_1,array);
    grid.setAdapter(ar);

Inside GetView() of your adapter

public View getView(int position, View convertView, ViewGroup container) {
        if(convertView == null) {
            convertView = LayoutInflator.from(getContext()).inflate(R.layout.single_list_row, container, false);
        }
        Pair<String, Integer> item = getItem(position);
        title.setCompoundDrawables(item.second, 0, 0, 0);
        return convertView;
    }
 };
Sign up to request clarification or add additional context in comments.

1 Comment

well title is the widget i am using..You can change it with your widget

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.