table.i中的textviews希望在提交按钮单击时对这些文本视图的用户输入

时间:2015-05-04 12:26:12

标签: android tablelayout

我想将用户输入设置为textlayout中的textviews,用于文字游戏应用程序。我是android新手,请帮我解决这个问题。

        tl = (TableLayout)findViewById(R.id.table);
        TableLayout.LayoutParams tablelparam = new TableLayout.LayoutParams(30,30);

        for (int r = 1; r <=9; r++) {
            r1= new TableRow(this);
            r1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
            for (int c = 1; c<=5; c++) {
                TextView txtview=new TextView(MainActivity.this);
                txtview.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
                txtview.setId(counter);
                counter++;
                txtview.setText( +counter + inputWord);
                r1.addView(txtview);
            }
            tl.addView(r1,new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));
        }

        Submit.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
            ArrayList<String>words = new ArrayList<String>();
            for (int j = 0; j < words.size(); j++) {
                TextView txtview = new TextView(MainActivity.this);
                txtview.setId(j);
                txtview.setText("" + words.get(j));
                txtview.getLayoutParams();
                t3.setText(t3.getText() + " " + txtview.getText()); 

            }
        };

1 个答案:

答案 0 :(得分:0)

为你在for循环中实例化的每个TextView设置onClickListener()。