문제

I am reading 10 lines (each cell separately) from an excel sheet and am displaying it in ListView. But I have an idea: instead of displaying it in a ListView, I want to display in a textView randomly. Here is the code for displaying in ListView I want it in textView Please help me

import java.io.InputStream;

import java.util.ArrayList;

import java.util.List; import android.os.Bundle; import android.app.Activity;

import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
    ListView lv;

    Readme r;
    InputStream ims;
    ArrayList<String> a123 = new ArrayList<String>();
    ArrayAdapter<String> ad;
    List<MyCustomPage> uuu = new ArrayList<MyCustomPage>();
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //tv=(TextView)findViewById(R.id.textView1);
        lv = (ListView)findViewById(R.id.listView1);
        r = new Readme();
        ims = getResources().openRawResource(R.raw.tips);
        r.setInputFile(ims);
        try {
            System.out.println("t1");
            uuu = r.read();
            System.out.println("t4");

        } catch (Exception e) {

            e.printStackTrace();
        }

        for (MyCustomPage m : uuu) {
            a123.add(m.getUserquate().trim());
        }
        ad = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, a123);
        lv.setAdapter(ad);
    }

}
`
도움이 되었습니까?

해결책

You could do like this.

You probably already have a Collection. Let's say: ArrayList a;

You can

Collection.shuffle(a);

and then get the first element like this:

String line = ""+a.get(0);

everytime you shuffle the 0 element would be different

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top