我从 Web 服务中获取 JSON 格式的数据,然后将数据放入自定义的ListView
.
单击 的项目时ListView
,我会打开一个新的Activity
. 现在我点击这个活动的“提交”按钮我回到同一个ListView
,
当我回到 时ListView
,我想更改我之前单击的 listitem 的文本
我只想刷新或重新调用活动时再次listticket.java
现在数据是静态的。我使用了网络服务。
listticket.java
public class listticket extends Activity {
static ListView listView;
ArrayList<String> aryTicket = new ArrayList<String>();
private String[] listArr = { "A", "B" };
private String[] listStatus = { "Alert", "Alert" };
private String[] listTicketid = { "1", "2" };
ArrayList<String> ary_ticket_code = new ArrayList<String>();
ArrayList<String> ary_address = new ArrayList<String>();
ArrayList<String> ary_ticketid = new ArrayList<String>();
public static ArrayList<String> ary_status = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listticket);
listView = (ListView) findViewById(R.id.itemList);
// filllistdata();
listArr = new String[ary_ticket_code.size()];
listArr = ary_ticket_code.toArray(listArr);
listStatus = new String[ary_status.size()];
listStatus = ary_status.toArray(listStatus);
listTicketid = new String[ary_ticketid.size()];
listTicketid = ary_ticketid.toArray(listTicketid);
MyArrayAdapter adapter = new MyArrayAdapter(this, listArr);
listView.setAdapter(adapter);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
ary_status.set(0, "Work Done");
((MyArrayAdapter) listView.getAdapter()).notifyDataSetChanged();
}
public class MyArrayAdapter extends ArrayAdapter<String> {
Activity context;
String[] listArr;
private TextView btnchkout;
// private final integer[] image;
public MyArrayAdapter(Activity context, String[] objects) {
super(context, R.layout.ticket, objects);
// TODO Auto-generated constructor stub
this.context = context;
listArr = objects;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.ticket, null, true);
TextView textView = (TextView) view.findViewById(R.id.txtTicketNo);
textView.setText(listArr[position]);
final TextView txtAlert = (TextView) view
.findViewById(R.id.txtAlert1);
// Toast.makeText(getApplicationContext(), listStatus[position],
// Toast.LENGTH_LONG).show();
String statusCheck = listStatus[position].toString().trim();
if (statusCheck.equals("Alert") == true) {
txtAlert.setText(statusCheck);
txtAlert.setTextColor(getResources().getColor(R.color.red));
} else if (statusCheck.equals("In Progress") == true) {
txtAlert.setText(statusCheck);
txtAlert.setTextColor(getResources().getColor(R.color.view));
} else if (statusCheck.equals("Work Complete Pending paperwork") == true) {
txtAlert.setText("Work Done");
txtAlert.setTextColor(getResources().getColor(R.color.green));
} else {
txtAlert.setText(statusCheck);
// txtAlert.setTextColor(getResources().getColor(R.color.defaulttextcolor));
}
final TextView btntextView = (TextView) view
.findViewById(R.id.btnCheckin);
if (statusCheck.equals("In Progress")) {
Drawable d = getResources().getDrawable(R.drawable.btncheckin);
btntextView.setBackgroundDrawable(d);
}
btnchkout = (TextView) view.findViewById(R.id.btnCheckout);
btnchkout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(listticket.this,
ticket_detail.class);
startActivity(intent);
}
});
return view;
}
}
}
单击 ListItem 时的另一个布局
票务细节.java
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket_detail);
btnSubmit = (TextView) findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new AsyncAction().execute(null,null,null);
//onBackPressed();
}
});
}
private class AsyncAction extends AsyncTask<String, Void, String>
{
public boolean status=false;
private ProgressDialog pd;
@Override
protected String doInBackground(String... arg0)
{
// TODO Auto-generated method stub
try
{
}
catch (Exception e)
{
// TODO: handle exception
}
return null;
}
@Override
protected void onPostExecute(String result)
{
pd.dismiss();
Intent intent = new Intent(ticket_detail.this,listticket.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
//finish();
}
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
pd = new ProgressDialog(ticket_detail.this);
pd.setMessage("Please Wait ...");
pd.setIndeterminate(true);
pd.setCancelable(false);
pd.show();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent a = new Intent(ticket_detail.this,listticket.class);
a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(a);
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}