从项目列表中自动选择

发布于 2024-12-24 19:16:31 字数 2025 浏览 1 评论 0原文

我有一堂课向我显示了项目列表。现在我正在通过单击(setOnItemClickListener)选择此项目,但我不想要这样。我想要的是:当我自动打开课程时,选择列表中的最后一项。

谁能告诉我该怎么做?

感谢您的帮助

public class SelectCodIncidence extends Activity {

private ArrayList<String> datos;
protected netAppApplication app;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.codincidence);
    datos = new ArrayList<String>();
    //datosCod = new ArrayList<String>();

    try {
        NotesCenter messageCenter = new NotesCenterImpl();

        List<CodIncidence> codincidence = messageCenter.getCodIncidence();                                      
        for (CodIncidence e : codincidence) {
            //datosCod.add("1");
            datos.add(e.id);

        }   
        } catch (Exception ex) {
        //  showMessage(ex);
            Log.v("blah", ex.getMessage());


        }

    ArrayAdapter<String> adaptador = 
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, datos);     

    final TextView lblMessage = (TextView)findViewById(R.id.MensajeCodIncidence);       
    final GridView grdOptions = (GridView)findViewById(R.id.GridCodIncidence);
    grdOptions.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, android.view.View v, int position, long id) {        

            CodIncidence codincidenceSelected = new CodIncidence();
            codincidenceSelected.id = datos.get(position);
            app = (netAppApplication)getApplicationContext();
            app.setcodincidenceActual(codincidenceSelected);
            SharedPreferences prefs = getSharedPreferences("netAppSetup",2);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("CODINCIDENCE", codincidenceSelected.id);
            editor.commit();
            finish();
        }
    });

    grdOptions.setAdapter(adaptador);
}

}

I have one class that shows me a list of Items. Right now I am selecting this items with click (setOnItemClickListener), but i don't want that. What i want is: when i open the class automatically is selecting the last item on the list.

Can anyone tell me how I can do it?

Thanks for any help

public class SelectCodIncidence extends Activity {

private ArrayList<String> datos;
protected netAppApplication app;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.codincidence);
    datos = new ArrayList<String>();
    //datosCod = new ArrayList<String>();

    try {
        NotesCenter messageCenter = new NotesCenterImpl();

        List<CodIncidence> codincidence = messageCenter.getCodIncidence();                                      
        for (CodIncidence e : codincidence) {
            //datosCod.add("1");
            datos.add(e.id);

        }   
        } catch (Exception ex) {
        //  showMessage(ex);
            Log.v("blah", ex.getMessage());


        }

    ArrayAdapter<String> adaptador = 
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, datos);     

    final TextView lblMessage = (TextView)findViewById(R.id.MensajeCodIncidence);       
    final GridView grdOptions = (GridView)findViewById(R.id.GridCodIncidence);
    grdOptions.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, android.view.View v, int position, long id) {        

            CodIncidence codincidenceSelected = new CodIncidence();
            codincidenceSelected.id = datos.get(position);
            app = (netAppApplication)getApplicationContext();
            app.setcodincidenceActual(codincidenceSelected);
            SharedPreferences prefs = getSharedPreferences("netAppSetup",2);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("CODINCIDENCE", codincidenceSelected.id);
            editor.commit();
            finish();
        }
    });

    grdOptions.setAdapter(adaptador);
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-12-31 19:16:31

像这样的东西:

Spinner spinner = (Spinner) findViewById(R.id.mySpinner);
int count = spinner.getCount();
if (count > 0){
    spinner.setSelection(count-1,true);
}

Something like:

Spinner spinner = (Spinner) findViewById(R.id.mySpinner);
int count = spinner.getCount();
if (count > 0){
    spinner.setSelection(count-1,true);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文