0
メソッドで送信されたJSONオブジェクトに基づいてUIを構築します。メソッドが実行されるたびに、新しい行がUIに追加されます。 JSONObject question
にアクセスするにはchartsButtonListenerが必要です。ボタンクリックからアクティビティを構築する
public void buildQuestions(JSONObject question) throws JSONException {
LayoutInflater inflater = (LayoutInflater) getActivity().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
questionContainer = (TableLayout) mainLayout.findViewById(R.id.questionContainer);
View questionBox = inflater.inflate(R.layout.question, null);
questionBox.setId(Integer.parseInt(question.getString("id")));
TextView title = (TextView) questionBox.findViewById(R.id.questionTextView);
title.setText(question.getString("title"));
//omitted code for verbosity
Button chartsButton = (Button) questionBox.findViewById(R.id.chartsButton);
Button submitButton = (Button) questionBox.findViewById(R.id.submitButton);
chartsButton.setOnClickListener(chartsListener);
submitButton.setOnClickListener(submitListener);
TableRow tr = (TableRow) questionBox;
TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT);
trParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(trParams);
LinearLayout progressRow = (LinearLayout) mainLayout.findViewById(R.id.progressRow);
progressRow.setVisibility(View.GONE);
questionContainer.addView(tr);
}
public OnClickListener chartsListener = new OnClickListener() {
public void onClick(View v) {
Intent chart = new Intent();
chart.setClass(getActivity(), Chart.class);
Log.v("", v.getParent().getClass().toString());//returns the TableRow
startActivity(chart);
}
};
私は精通していますが、余分な置くが、私は単に直接リスナーに質問オブジェクトを渡すことができますので、私は前方に意図に沿って、その後できればそれがベストです。助言がありますか?