如何在makeHttpRequest(url," POST",params)方法中传递相同类型的数据数组?

时间:2014-08-26 12:21:47

标签: android mysql sql database sqlite

我在android中创建了一个应用程序来更新所有使用JSON,php,MYSQL的学生的出勤率。 当我通过单一值时,它有效,但我想通过存储在一个学生中的所有学生的出勤率 数组名为String []的值。如何做到我无法做到这一点。我已经通过谷歌,但一切都是徒劳的

以下是我的申请图片http://s12.postimg.org/ymjsny91p/new.png

LinearLayout lin = (LinearLayout) findViewById(R.id.myLinear);
int i;
for(i=0;i<jArray.length();i++){
    try {
        JSONObject arrayobj=jArray.getJSONObject(i);
        roll_num=arrayobj.getString(TAG_ROLL);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

          TextView myText = new TextView(getApplicationContext());
          myText.setText(""+roll_num);
          myText.setTextSize(20);
          lin.addView(myText);
    }
LinearLayout lin_4 = (LinearLayout) findViewById(R.id.myLinear_4);
 for (int j = 0; j < jArray.length() ; j++)
  {
        final int k=j;
       final TextView myText_4 = new TextView(getApplicationContext());
       myText_4.setId(j);
       myText_4.setText("Select");
       myText_4.setTextSize(20);
       lin_4.addView(myText_4);
       myText_4.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
                 if((myText_4.getText().toString()).equals("Select")) myText_4.setText("Present");
                 else if((myText_4.getText().toString()).equals("Absent")) myText_4.setText("Present");
                 else if((myText_4.getText().toString()).equals("Present")) myText_4.setText("Absent");
                showtoast();
        }

        private void showtoast() {
            // TODO Auto-generated method stub
            String[] values=new String[26];
            values[k]=myText_4.getText().toString();
        }
    });      
  }
}

}

1 个答案:

答案 0 :(得分:0)

    LinearLayout lin_4 = (LinearLayout) findViewById(R.id.myLinear_4);

    for (int j = 0; j < 26; j++) {
        final TextView myText_4 = new TextView(this);
        myText_4.setText("Absent");
        myText_4.setTextSize(20);
        myText_4.setId(j);
        lin_4.addView(myText_4);
        myText_4.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                TextView txt = (TextView) arg0;
                if ((txt.getText().toString()).equals("Present"))
                    txt.setText("Absent");
                else if ((myText_4.getText().toString()).equals("Absent"))
                    txt.setText("Present");
                /*
                 * bcz u r using the textview instance which is created
                 * last.when on click event will fire it will return u the
                 * instance of the textview which is being clicked
                 */

                // if((myText_4.getText().toString()).equals("Present"))
                // myText_4.setText("Absent");
                // else if((myText_4.getText().toString()).equals("Absent"))
                // myText_4.setText("Present");
            }
        });
    }

我对此类事情的建议是使用listview

我在点击事件方法中提到了你的错误。