2016-08-24 51 views
0

我正在嘗試在url中接收整數。將值傳遞給活動並在url中將它們重新採用

這如何傳遞值從一個活動到另一:

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); 
     } 
    }); 
} 

SubCategory.class我接收它像這樣

@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"); 
} 

現在的值被存儲在變量recivedId其是1或2或3或4 我想要做的就是執行這個像這樣的JSONTask url

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

,以便最終網址看起來像這樣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

真棒,謝謝! –

相關問題