sách gpt4 ai đã đi

Tôi có hai hoạt động. Tôi muốn gửi dữ liệu từ Hoạt động thứ hai đến Hoạt động trước đó. Hoạt động đầu tiên có Listview tùy chỉnh

In lại Tác giả: Space Dog 更新时间:2023-10-29 16:35:18 29 4
mua khóa gpt4 Nike

我有两个 Activity 。我想将数据从第二个 Activity 发送到上一个 Activity 。第一个 Activity 有自定义 ListView 和 bean 类。当我点击第二个 Activity 时,拳头 Activity 以字符串形式获取数据。我的问题我将如何在自定义 ListView 上显示提取数据

我的第一个 Activity 是..

package com.firstchoicefood.phpexpertgroup.firstchoicefoodin;
import android.app.ActionBar;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AbsListView;
import android.os.Bundle;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

import com.firstchoicefood.phpexpertgroup.firstchoicefoodin.adapter.ListAdapterAddItems;
import com.firstchoicefood.phpexpertgroup.firstchoicefoodin.bean.ListModel;
import com.firstchoicefood.phpexpertgroup.firstchoicefoodin.json.JSONfunctions;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.URLEncoder;
import java.util.ArrayList;

nhập android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class DetaisRESTActivity extends Activity {
String totalamount,valueid,valueid1,valuename;

public String countString=null;
public int count=0;
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
public TextView mTitleTextView;
public ImageButton imageButton;
ListAdapterAddItems adapter;
public TextView restaurantname = null;
public TextView ruppees = null;
String restaurantmenuname,rastaurantname;

ProgressDialog mProgressDialog;
ArrayList arraylist;
public static String RASTAURANTNAMEDETAILS = "RestaurantPizzaItemName";
public static String RASTAURANTRUPPEES = "RestaurantPizzaItemPrice";

@Ghi đè
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_detais_rest);
// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);
ActionBar actionBar = getActionBar();

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));

LayoutInflater mInflater = LayoutInflater.from(this);

View mCustomView = mInflater.inflate(R.layout.titlebar, null);
mTitleTextView = (TextView) mCustomView.findViewById(R.id.textView123456789);


imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton2);


actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);

Intent intent = getIntent();
// get the extra value
valuename = intent.getStringExtra("restaurantmenuname");
valueid = intent.getStringExtra("restaurantmenunameid");
valueid1 = intent.getStringExtra("idsrestaurantMenuId5");
//totalamount = intent.getStringExtra("ruppees");
Log.i("valueid",valueid);
Log.i("valuename",valuename);
Log.i("valueid1",valueid1);
// Log.i("totalamount",totalamount);
new DownloadJSON().execute();






}


// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask {

@Ghi đè

protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(DetaisRESTActivity.this);
// Set progressdialog title
mProgressDialog.setTitle("Android JSON Parse Tutorial");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
Toast.makeText(DetaisRESTActivity.this, "Successs", Toast.LENGTH_LONG).show();
}

@Ghi đè
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList();
// Retrieve JSON Objects from the given URL address
// Log.i("123",value1);
jsonobject = JSONfunctions.getJSONfromURL("http://firstchoicefood.in/fcfapiphpexpert/phpexpert_restaurantMenuItem.php?r=" + URLEncoder.encode(valuename) + "&resid=" + URLEncoder.encode(valueid1) + "&RestaurantCategoryID=" + URLEncoder.encode(valueid) + "");



thử {

// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("RestaurantMenItems");
Log.i("1234",""+jsonarray);

for (int i = 0; i < jsonarray.length(); i++) {

jsonobject = jsonarray.getJSONObject(i);


ListModel sched = new ListModel();
sched.setProductName(jsonobject.getString("RestaurantPizzaItemName"));

sched.setPrice(jsonobject.getString("RestaurantPizzaItemPrice"));

arraylist.add(sched);

}
} bắt (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
trả về giá trị null;
}

@Ghi đè
protected void onPostExecute(Void args) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listViewdetails);

adapter = new ListAdapterAddItems();

listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();



listview.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Ghi đè
public void onItemClick(AdapterView arg0, View arg1, int position, long arg3)
{

// Get Person "behind" the clicked item
ListModel p =(ListModel)listview.getItemAtPosition(position);
// Log the fields to check if we got the info we want

Log.i("SomeTag", "Persons name: " + p.getProductName());
Log.i("SomeTag", "Ruppees: " + p.getPrice());





đếm++;
countString=String.valueOf(count);
Toast toast = Toast.makeText(getApplicationContext(),
"Item " + (position + 1),
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();

Toast.makeText(getBaseContext(),
countString, Toast.LENGTH_LONG).show();

mTitleTextView.setText(countString);
Intent intent=new Intent(DetaisRESTActivity.this,QuentityActivity.class);
intent.putExtra("quentity",countString);
intent.putExtra("valueid",valueid);
intent.putExtra("valuename",valuename);
intent.putExtra("valueid1",valueid1);

intent.putExtra("name",p.getProductName());
intent.putExtra("price",p.getPrice());
startActivityForResult(intent,2);
// startActivity(intent);

}
});
imageButton.setOnClickListener(new View.OnClickListener() {


@Ghi đè
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Refresh Clicked!",
Toast.LENGTH_LONG).show();
Intent i=new Intent(DetaisRESTActivity.this,TotalPriceActivity.class);
startActivity(i);
}
});
}
}
// Call Back method to get the Message form other Activity
@Ghi đè
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
if(requestCode==2)
{

String message=data.getStringExtra("MESSAGE");
Log.i("xxxxxxxxxxx",message);
ruppees.setText(message);

}
}
//==========================
class ListAdapterAddItems extends ArrayAdapter
{
ListAdapterAddItems(){
super(DetaisRESTActivity.this,android.R.layout.simple_list_item_1,arraylist);
//imageLoader = new ImageLoader(MainActivity.this);
}
@Ghi đè
công khai View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if(convertView == null){
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.cartlistitem, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}khác{
holder = (ViewHolder)convertView.getTag();
}
holder.populateFrom(arraylist.get(position));
trả về convertView;
}
}

class ViewHolder {



ViewHolder(View row) {
restaurantname = (TextView) row.findViewById(R.id.rastaurantnamedetailsrestaurant);
ruppees = (TextView) row.findViewById(R.id.rastaurantcuisinedetalsrestaurant);

}

// Notice we have to change our populateFrom() to take an argument of type "Person"
void populateFrom(ListModel r) {
restaurantname.setText(r.getProductName());
ruppees.setText(r.getPrice());

}


}


















@Ghi đè
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_detais_rest, menu);
trả về giá trị đúng;
}

@Ghi đè
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.


return super.onOptionsItemSelected(item);
}

}

我的第二个 Activity 是......

package com.firstchoicefood.phpexpertgroup.firstchoicefoodin;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.firstchoicefood.phpexpertgroup.firstchoicefoodin.bean.ListModel;
import com.firstchoicefood.phpexpertgroup.firstchoicefoodin.json.JSONfunctions;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.URLEncoder;
import java.util.ArrayList;


public class QuentityActivity extends Activity {
String value=null;
public String TotAmt=null;
String Name;
ImageButton positive,negative;

int count = 0;
int tot_amt = 0;
public String countString=null;
String Rs,name,price;
String valueid,valueid1,valuename;
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
public TextView ruppees,submenuname,totalruppees,quantity,addtocart;


ProgressDialog mProgressDialog;
ArrayList arraylist;
@Ghi đè
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quentity);
ActionBar actionBar = getActionBar();

// Enabling Up / Back navigation
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
Intent intent = getIntent();
// get the extra value
value = intent.getStringExtra("quentity");
valuename = intent.getStringExtra("valuename");
valueid = intent.getStringExtra("valueid");
valueid1 = intent.getStringExtra("valueid1");
name=intent.getStringExtra("name");
price=intent.getStringExtra("price");
Log.i("valueid",valueid);
Log.i("valuename",valuename);
Log.i("valueid1",valueid1);
Log.i("name",name);
Log.i("price",price);
quantity=(TextView)findViewById(R.id.rastaurantcuisinedetalsrestaurantquantity);
totalruppees=(TextView)findViewById(R.id.rastaurantnamequentitytotal1);
submenuname=(TextView)findViewById(R.id.rastaurantnamesubmenuquentity);
ruppees=(TextView)findViewById(R.id.rastaurantnamequentity1);
positive=(ImageButton)findViewById(R.id.imageButtonpositive);
negative=(ImageButton)findViewById(R.id.imageButtonnegative);
addtocart=(TextView)findViewById(R.id.textViewaddtocart);
buttonclick();
addtocart();
// value1 = intent.getStringExtra("numericitem");
// int numericvalue = intent.getIntExtra("numericitem", 11);
Log.i("value", value);
submenuname.setText(name);
ruppees.setText(price);
totalruppees.setText(price);
// new DownloadJSON().execute();
}


public void addtocart(){
addtocart.setOnClickListener(new View.OnClickListener() {
@Ghi đè
public void onClick(View v) {
Intent intent=new Intent();
intent.putExtra("MESSAGE",TotAmt);
setResult(2,intent);
finish();//finishing activity

}
});
}

@Ghi đè
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_quentity, menu);
trả về giá trị đúng;
}

@Ghi đè
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
trả về giá trị đúng;
}

return super.onOptionsItemSelected(item);
}
}

1 Câu trả lời

public void addtocart(){
addtocart.setOnClickListener(new View.OnClickListener() {
@Ghi đè
public void onClick(View v) {
Intent intent=new Intent(QuentityActivity.this,DetaisRESTActivity.class);
intent.putExtra("MESSAGE",TotAmt);
startActivity(intent);
finish();//finishing activity
}
});
}

然后在第一个 Activity 中:

@Ghi đè
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent c = getIntent();
String mg = c.getStringExtra("MESSAGE");
}

现在你可以在你想要的地方显示 Sợi dây 了。

关于android - 我有两个 Activity 。我想将数据从第二个 Activity 发送到上一个 Activity 。第一个 Activity 有自定义 Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30316455/

29 4 0
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com