2016-08-24 11 views
0

urlで整数を受け取ろうとしています。値をアクティビティに渡してURLで受け取る

iを1つの活動から別の値を渡す方法対象:SubCategory.class

private void displayCategoriesInformation(CategoriesModel categoriesModel) { 
    //get references to your views 
    TextView tvCategoryId = (TextView) findViewById(R.id.tvCategoryId); 

    final int categoryId = categoriesModel.getId(); 


    //set values from your categoriesModel java object to textView 
    tvCategoryId.setText("Id : " + categoriesModel.getId()); 

    okButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 

      Intent intent = new Intent(Categories.this, SubCategories.class); 
      intent.putExtra("parameter_name", categoryId); 
      startActivity(intent); 
     } 
    }); 
} 

今値をどの変数recivedIdに格納され、この

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.row_subcategory); 

    Intent intent = getIntent(); 
    int recivedId = intent.getIntExtra("parameter_name", 2); 

    TextView tvRecivedId = (TextView) findViewById(R.id.tvRecivedId); 
    tvRecivedId.setText("recivedId" + recivedId); 
    dialog = new ProgressDialog(this); 
    dialog.setIndeterminate(true); 
    dialog.setCancelable(false); 
    dialog.setMessage("Loading, please wait....."); 

    spinnerFood = (Spinner) findViewById(R.id.spinFood); 
    okButton = (Button) findViewById(R.id.bOk); 
    // spinner item select listener 
    spinnerFood.setOnItemSelectedListener(this); 
    new JSONTask().execute("http://146.185.178.83/resttest/subCategories"); 
} 

ようにそれを受け取ります1または2または3または4です これを実行すると、このJSONTask URLが実行されます

new JSONTask().execute("http://146.185.178.83/resttest/categories/recivedId/subCategories"); 

はとてもエンドのURLは次のようになり、このhttp://146.185.178.83/resttest/categories/1/subcategories/

私は達成することができますどのようにこの

答えて

0
String url = "http://146.185.178.83/resttest/categories/" + recivedId +"/subcategories/"; 
new JSONTask().execute(url); 
+0

素晴らしい、ありがとうございました! –

関連する問題