【问题标题】:how to pass array of data of same type in makeHttpRequest(url,"POST",params) method?如何在 makeHttpRequest(url,"POST",params) 方法中传递相同类型的数据数组?
【发布时间】:2014-08-26 12:21:47
【问题描述】:

我在 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();
        }
    });      
  }
}

}

【问题讨论】:

  • onCreate 中而不是在 onClick 中创建两个编辑文本

标签: android mysql sql database sqlite


【解决方案1】:
    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

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

猜你喜欢
  • 1970-01-01
  • 2017-10-13
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
  • 1970-01-01
  • 2018-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多