私は動的テーブル行を含むテーブルを作成しました。各テーブルの行には、5つのテキストビューが含まれています。リージョン名、地域コード、ターゲットなどのデータが含まれています。私はテーブル行OnclickListnerを実装しているので、ユーザーは別のアクティビティの特定のデータを表示するためにテーブル行を選択できます。問題は各表の行です。別のアクティビティーに渡すためには、異なるregionCodeが必要です。私はこれを別のアクティビティにどのように渡すことができますか?文字列配列を使用しようとしましたが、ヌルポイント例外が表示されます。テーブル内の選択基準のテーブル行を選択して別のアクティビティに異なる値を渡す方法
これはBRANCHFLAGは帯状
else if(branchFlag.equals("Z"))
{
final List<NameValuePair> details = new ArrayList<NameValuePair>(1);
details.add(new BasicNameValuePair("branchCode", branchCode));
details.add(new BasicNameValuePair("branchFlag", branchFlag));
details.add(new BasicNameValuePair("finYr",finyear));
details.add(new BasicNameValuePair("month", month_number));
Log.d("month_num", month_number);
response = apc.postURL(RETRIEVE_BRANCH_MIS_DETAILS_LINK, details);
Log.d("**************", RETRIEVE_BRANCH_MIS_DETAILS_LINK + details);
Log.d("RETRIEVE_MainMis_DETAILS_LINK", response);
try {
JSONObject jsonObject = new JSONObject(response);
jsonArray = jsonObject.getJSONArray("result");
errorflag = jsonObject.getString("errorFlag");
errormsg = jsonObject.getString("errorMsg");
if (errorflag.equals("N"))
{
// adding 4 data sections to the table row
TextView label_product = new TextView(MainMis.this);
label_product.setId(0);
label_product.setText(" Region ");
label_product.setTextColor(Color.WHITE);
tr_head.addView(label_product);// add the column to the table row here
TextView label_target = new TextView(MainMis.this);
label_target.setId(0);// define id that must be unique
label_target.setText(" Target "); // set the text for the header
label_target.setTextColor(Color.WHITE); // set the color
label_target.setPadding(5, 5, 5, 5);
label_target.setGravity(5); // set the padding (if required)
// label_target.setWidth(10);
tr_head.addView(label_target); // add the column to the table row here
TextView label_achievement = new TextView(MainMis.this);
label_achievement.setId(0);
label_achievement.setText(" Achievement");
label_achievement.setTextColor(Color.WHITE);
label_achievement.setPadding(5, 5, 5, 5);
label_achievement.setGravity(5);
// label_achievement.setWidth(50);
tr_head.addView(label_achievement);
TextView label_shortfall = new TextView(MainMis.this);
label_shortfall.setId(0);
label_shortfall.setText(" Shortfall");
label_shortfall.setTextColor(Color.WHITE);
label_shortfall.setPadding(5, 5, 5, 5);
label_shortfall.setGravity(5);
// label_achievement.setWidth(50);
tr_head.addView(label_shortfall);
TextView label_ranking = new TextView(MainMis.this);
label_ranking.setId(0);
label_ranking.setText(" Ranking ");
label_ranking.setTextColor(Color.WHITE);
label_ranking.setPadding(5, 5, 5, 5);
label_ranking.setGravity(5);
tr_head.addView(label_ranking);
// add the table row the the main table layout that we fetched at the start
tl.addView(tr_head, new TableLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
TextView[] textArray = new TextView[jsonArray.length()];
TableRow[] tr_head1 = new TableRow[jsonArray.length()];
try {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(2);// set as you need
int i = 0;
int j = 0;
for (i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonobj = jsonArray.getJSONObject(i);
// JSONObject productData = product.getJSONObject("Product");
// String productDescription = product.getString("achievementPer");
DecimalFormat df = new DecimalFormat("#");
incomeAmount = ((jsonobj.getString("AchievementSum")));
excShort = ((jsonobj.getString("excShort")));
String excShort1 = excShort.replace(",", ".");
Double excShort2 = Double.parseDouble(excShort1);
Log.d("excShort, replace ,", excShort1);
Log.d("excShort in point format,", excShort1);
targetAmount = ((jsonobj.getString("targetSum")));
//ADDED BY SOORAJ
Regions = ((jsonobj.getString("regionName")));
zoneName=((jsonobj.getString("zonalName")));
Log.d("achievementPer123", String.valueOf((((excShort)))));
//Create the tablerows
tr_head1[i] = new TableRow(MainMis.this);
tr_head1[i].setClickable(true);
tr_head1[i].setId(i + 1);
if ((i % 2) == 0) {
tr_head1[i].setBackgroundColor(Color.LTGRAY);
} else {
Resources resource = getApplicationContext().getResources();
tr_head1[i].setBackgroundColor(resource.getColor(R.color.white_overlay));
}
// tr_head1[i++].setBackgroundColor(Color.YELLOW);
tr_head1[i].setLayoutParams(new TableLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
// Here create the TextView dynamically
textArray[i] = new TextView(MainMis.this);
//Modified
//
textArray[i].setId(i + 111);
textArray[i].setText(" " + Regions);
textArray[i].setTextColor(Color.BLACK);
textArray[i].setPadding(5, 5, 5, 5);
tr_head1[i].addView(textArray[i]);
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(targetAmount));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
tr_head1[i].addView(textArray[i]);
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(incomeAmount));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
tr_head1[i].addView(textArray[i]);
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(excShort));
if (excShort2 > 0) {
textArray[i].setTextColor(Color.BLUE);
} else {
textArray[i].setTextColor(Color.RED);
}
// textArray[i].setWidth(120);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(5);
tr_head1[i].addView(textArray[i]);
//ADDED BRANCH RANKING
textArray[i] = new TextView(MainMis.this);
textArray[i].setId(i + 111);
textArray[i].setText(String.valueOf(Rgn_Ranking));
textArray[i].setTextColor(Color.BLACK);
// textArray[i].setWidth(10);
textArray[i].setPadding(5, 5, 5, 5);
textArray[i].setGravity(Gravity.CENTER|Gravity.BOTTOM);
tr_head1[i].addView(textArray[i]);
tl.setVisibility(View.VISIBLE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
if (tr_head1.length > 0)
{
tl.addView(tr_head1[i], new TableLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
length = String.valueOf(tr_head1.length);
Log.d("LENGTH OF ARRAY", String.valueOf(length));
//Make the table row onClickable
tr_head1[i].setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent a=new Intent(MainMis.this,RegionMIS.class);
Bundle extras = a.getExtras();
startActivity(a);
}
});
}
}
if ((i == 0)) {
Log.d("No rows to display **", "");
tl.setVisibility(View.GONE);
l2.setVisibility(View.VISIBLE);
l3.setVisibility(View.GONE);
//Toast.makeText(MainMis.this, "No data to display", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("ERROR...", e.getMessage().toString());
}
} else {
tl.setVisibility(View.GONE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
l4.setVisibility(View.VISIBLE);
errormsgedit.setText(errormsg);
}
} catch (Exception ex) {
ex.printStackTrace();
Log.d("ERROR...ERROR..", ex.getMessage().toString());
}
}
ブロののonClick LISTNERでこれを添加しましたオブジェクト..と私は別のクラスに渡したいと思います。問題は私がそれを宣言する方法を見つけることができないと私はurコードを試した..それはアプリをクラッシュ.. –
あなたはJSONから解析しているregionCodeをどこに格納していますか? – PsyGik
このアプリは、MISアイコンをクリックすると、テーブルビューの会社のゾーンデータが管理ヘッドに表示されるように機能します。ゾーンテーブルでは、領域を行として表示します。行の数に等しい数の領域があります。各領域にはregionCodeがあります。領域を含む特定の行をクリックすると、その領域のMISを新しいページが表示します。その枝の下にブランチを表示してください...あなたはコンセプトを理解していますか? –