am having a two editbox. the values enter in that has to placed in the custom listview its working fine for this...
but i want to save this values in the list view permanently.so that if the phones switches off and again run the app then the values have to be saved ..like phone contact number and name have to be saved..
here am ataching the code
public class Editcard extends Activity{
EditText cardname,cardDescription ;
MyApplication app;
#SuppressWarnings({ "unchecked", "rawtypes" })
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.editcredit);
app = ((MyApplication) getApplicationContext());
cardname =(EditText)findViewById(R.id.cardash);
cardDescription =(EditText)findViewById(R.id.editdescription);
Button save =(Button)findViewById(R.id.save);
save.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
app.carddata =cardname.getText().toString();
System.out.println("Gotcardname"+app.carddata);
app.descriptiondata =cardDescription.getText().toString();
System.out.println("gotDescription"+app.descriptiondata);
app.arryList.add(app.carddata);
app.arryList1.add(app.descriptiondata);
Intent saveIntent =new Intent(Editcard.this,Newcard.class);
startActivity(saveIntent);
}
});
}
}
public class MyApplication extends Application{
ArrayList<String> arryList = new ArrayList<String>();
ArrayList<String> arryList1 = new ArrayList<String>();
String carddata,descriptiondata,=null;
}
public class Newcard extends Activity {
MyAdapter adapter;
ListView listView;
LayoutInflater lay;
MyApplication app;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newcard);
app = ((MyApplication) getApplicationContext());
TextView newcard =(TextView)findViewById(R.id.newcard);
newcard.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent card = new Intent(Newcard.this,Editcreditcard.class);
startActivity(card);
}
});
listView = (ListView) findViewById(R.id.cardlist);
adapter =new MyAdapter(this, app.arryList,app.arryList1);
listView.setAdapter(adapter);
}
public class MyAdapter extends BaseAdapter {
Context context = null;
ArrayList<String> items= null;
ArrayList<String> items1= null;
public MyAdapter(Newcard newcard, ArrayList<String> items,
ArrayList<String> items1) {
// TODO Auto-generated constructor stub
this.items = items;
this.items1 = items1;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items;
//return items.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View layout = null;
TextView produ = null;
TextView desc = null;
if (convertView == null) {
lay = LayoutInflater.from(getApplicationContext());
layout = lay.inflate(R.layout.customlist, null);
} else {
layout = convertView;
}
produ = (TextView) layout.findViewById(R.id.card);
produ.setText("" +app.arryList.get(position));
desc= (TextView) layout.findViewById(R.id.descrip);
desc.setText("" +app.arryList1.get(position));
return layout;
}
}
}
use can use SharedPreferences, that will save your values permanently, untill they are changed(by changing values in editbox) or user reinstall (clear data) application. Shared Preferences works like this
// save string in sharedPreferences
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
editor.putString("some_key", string); // here string is the value you want to save
editor.commit();
// restore string in sharedPreferences
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
string = settings.getString("some_key", "");
Related
I'm trying to build an Attendance Manager app for students and am using a custom ListView to display subject names and minimum attendance when tapped on.
These are the Issues I'm facing::
1) I want my first list item to be an "Add a subject item" and on tapping on that it goes to AddSubjectActivity and stores everything via SharedPreferences.
2)Once the submit button is pressed in the AddSubjectActivity i want the next list item to say "Tap to add a subject" and so on.
3) Basically ,suppose the ListView has 5 items, tapping on each item takes me to the AddSubject Activity, but information corresponding to the respective list Item being tapped is displayed in it.
This is my Code:
Class CustomAdapter
public class CustomAdapter extends BaseAdapter{
String [] result;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(SecondActivity mainActivity, String[] prgmNameList, int[] prgmImages) {
// TODO Auto-generated constructor stub
result=prgmNameList;
context=mainActivity;
imageId=prgmImages;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return result.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView tv;
ImageView img;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
SecondActivity second=new SecondActivity();
View rowView;
rowView = inflater.inflate(R.layout.program_list, null);
holder.tv=(TextView) rowView.findViewById(R.id.textView);
holder.img=(ImageView) rowView.findViewById(R.id.statsImageView);
holder.tv.setText(result[position]);
holder.img.setImageResource(imageId[position]);
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
context.startActivity(new Intent(context, AddSubject.class));
}
});
return rowView;
}
}
SecondActivity: The Activity that contains the ListView
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Bundle bundle=getIntent().getExtras();
String fullNameFinal = bundle.getString("fullName");
String courseFinal = bundle.getString("course");
int avgAttendanceFinal= bundle.getInt("avgAttendance");
boolean logInStatusFinal = bundle.getBoolean("logInStatus");
nameTextView=(TextView)findViewById(R.id.nameTextView);
courseTextView=(TextView)findViewById(R.id.courseTextView);
nameTextView.setText(fullNameFinal);
courseTextView.setText(courseFinal);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
ListView lv;
Context context;
ArrayList prgmName;
int [] prgmImages={R.drawable.listblockgold,R.drawable.listblockindigo,R.drawable.listblocklime,R.drawable.listblockorange,R.drawable.listblockpink,R.drawable.listblockred,R.drawable.listblocksilver,R.drawable.listblocktan,R.drawable.listblockteal};
String [] prgmNameList={"Maths","P.Comm.","IOT","Operating Systems","Web Programming","DSP","PHP","Jquery","JavaScript"};
context=this;
lv=(ListView) findViewById(R.id.testListView);
lv.setAdapter(new CustomAdapter(this, prgmNameList,prgmImages));
`AddSubject Activity`
public class AddSubject extends AppCompatActivity {
//Buttons
Button missedMinus;
Button missedPlus;
//ButtonsEnd
//TextViews
TextView safeBunksNumber;
TextView missedLectures;
TextView totalLecturesTextView ;
TextView percentageTextView;
//TextViewsEnd
EditText missedLecturesTextView;
ProgressBar progressBar;
static String s= Integer.toString(10);
public void missedMinusClick(View view)
{
totalLecturesTextView=(TextView)findViewById(R.id.totalLecturesTextView);
int totalLectures= Integer.parseInt(totalLecturesTextView.getText().toString());
missedLecturesTextView=(EditText)findViewById(R.id.missedLecturesTextView);
int missedLectures= Integer.parseInt(missedLecturesTextView.getText().toString());
missedLecturesTextView.setText(Integer.toString(missedLectures-1));
safeBunksNumber=(TextView)findViewById(R.id.safeBunksNumber);
int safeBunksNumber;
}
public void missedPlusClick(View view2)
{
missedLecturesTextView=(EditText)findViewById(R.id.missedLecturesTextView);
int missedLectures= Integer.parseInt(missedLecturesTextView.getText().toString());
missedLecturesTextView.setText(Integer.toString(missedLectures+1));
}
public void submitOnClick1(View view3)
{
EditText subName = (EditText)findViewById(R.id.subName);
EditText totalLecturesTextView = (EditText)findViewById(R.id.totalLecturesTextView);
EditText missedLecturesTextView =(EditText)findViewById(R.id.missedLecturesTextView);
String subjectName = subName.getText().toString();
int totalLectures = Integer.parseInt(totalLecturesTextView.getText().toString());
int missedLectures = Integer.parseInt(missedLecturesTextView.getText().toString());
SharedPreferences sharedPreferences = this.getSharedPreferences("com.example.yashrandive.attendancemanager", Context.MODE_PRIVATE);
sharedPreferences.edit().putString("subName",subjectName);
sharedPreferences.edit().putInt("totalLectures",totalLectures);
sharedPreferences.edit().putInt("missedLectures",missedLectures);
}
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_subject);
}
}
I have one listview and adapter ImageButton for delete data, but I don't know how to delete data by setOnClick. I need to click ImageButton and delete data. I have data type room not null.
public class OrgManageRoom extends AppCompatActivity {
private ListView listView;
private ArrayAdapter<String> arrayAdapter;
private ArrayList<String> list_of_rooms = new ArrayList<>();
ArrayList<HashMap<String, String>> MyArrList;
public ArrayList<String> arr;
public ArrayAdapter adapter;
private DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().getRoot();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_org_manage_room);
// listView = (ListView)findViewById(R.id.listView);
// listView.setAdapter(new ImageAdapter(this));
// arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list_of_rooms);
// listView.setAdapter(arrayAdapter);
createAdapter();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(OrgManageRoom.this,OrgAddUser.class);
startActivity(i);
}
});
}
private void createAdapter() {
listView = (ListView)findViewById(R.id.listView);
listView.setAdapter(new ImageAdapter(this));
mDatabase = FirebaseDatabase.getInstance().getReference().child("AllRoom");
mDatabase.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Set<String> set = new HashSet<String>();
Iterator i = dataSnapshot.getChildren().iterator();
while (i.hasNext()){
set.add(((DataSnapshot)i.next()).getKey());
}
list_of_rooms.clear();
list_of_rooms.addAll(set);
// arrayAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context c) {
// TODO Auto-generated method stub
context = c;
}
public int getCount() {
// TODO Auto-generated method stub
return list_of_rooms.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.deleteroom, null);
}
// ColImgID
TextView txtPosition = (TextView) convertView.findViewById(R.id.ColImgDesc);
txtPosition.setPadding(10, 0, 0, 0);
txtPosition.setText(list_of_rooms.get(position));
ImageButton cmdShared = (ImageButton) convertView.findViewById(R.id.imgCmdShared);
cmdShared.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(OrgManageRoom.this, "test" + list_of_rooms.get(position), Toast.LENGTH_LONG).show();
}
});
return convertView;
}
}
}
Sorry, I edit all code and I make project chat firebase and show listview listroom for add user and delete user and manageroom. It deletes room edit nameroom. Same I need to click imagebutton for delete listroom.
Hi I can not delete a row from list View i don't know how to delete it i search a lot from Internet i try out many examples but yet i can't solve the issue . when i click the hldr.delete button the complete row of list View delete from the list solution pls.
PlaceOrder Activity
public class PlaceOrder extends Activity {
String [] pIds;
String [] pNames;
String [] pPrizes;
static ListView lv;
ImageView bck;
String [] listImages;
String food_id;
String userdata[];
Intent i;
TextView totalprze;
float tprize;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place_order);
lv=(ListView)findViewById(R.id.cart_list);
bck=(ImageView) findViewById(R.id.placeholder_bg_btn);
totalprze =(TextView) findViewById(R.id.place_order_price);
i=new Intent(this,Menu.class);
bck.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bundle bundle=new Bundle();
//bundle.putStringArray("images", ListImages);
bundle.putString("food_id", food_id);
bundle.putStringArray("images", listImages);
bundle.putStringArray("userData",userdata);
i.putExtras(bundle);
startActivity(i);
}
});
if(this.getIntent().getExtras()!=null)
{
Bundle b=this.getIntent().getExtras();
pIds=b.getStringArray("pId");
pNames=b.getStringArray("PName");
pPrizes=b.getStringArray("pPrize");
userdata=b.getStringArray("userData");
tprize=b.getFloat("totalprize");
food_id=b.getString("food_id");
listImages=b.getStringArray("images");
String prz=Float.toString(tprize);
totalprze.setText("$"+prz);
lv.setAdapter(new cartAdapter(PlaceOrder.this, pIds, pNames, pPrizes,userdata));
pIds=null;
pNames=null;
pPrizes=null;
}
}
public void onBackPressed() {
pIds=null;
pNames=null;
pPrizes=null;
}
}
CartAdapter
public class cartAdapter extends BaseAdapter{
String [] pIdz;
String [] pNamz;
String [] pPrizs;
String [] userData;
// List<String> imges;
Context context;
// private ShopingCartHelper obj;
private static LayoutInflater inflater=null;
JSONArray jCat = null;
int count=0;
ProgressDialog pDialog;
public cartAdapter(PlaceOrder ctx,
String[] pIds,String[] pNams, String[] pprise,String [] userdata) {
pIdz=pIds;
pNamz=pNams;
context=ctx;
pPrizs=pprise;
userData=userdata;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// TODO Auto-generated constructor stub
}
#Override
public int getCount() {
// TODO Auto-generated method stub
if(pIdz==null){
Toast.makeText(context, "There is issue with net connection.", Toast.LENGTH_LONG).show();
//Intent i=new Intent(context,WelcomeActivity.class);
//context.startActivity(i);
return count ;
}else{
return pIdz.length;
}
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class holder{
TextView pid;
TextView pname;
TextView pprise;
Button delete;
ListView lv;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final holder hldr=new holder();
View rowView = null;
Bitmap bitmap = null;
rowView = inflater.inflate(R.layout.place_order_item_list, null);
hldr.pid=(TextView) rowView.findViewById(R.id.item_id);
hldr.pname=(TextView) rowView.findViewById(R.id.item_name);
hldr.pprise=(TextView) rowView.findViewById(R.id.item_price);
hldr.delete=(Button) rowView.findViewById(R.id.delete);
hldr.pid.setText(pIdz[position]);
hldr.pname.setText(pNamz[position]);
hldr.pprise.setText(pPrizs[position]);
/* convertView.setTag(hldr);
hldr.delete.setTag(hldr);*/
//
// Picasso.with(context).load(imgs[position]).into(hldr.img);
hldr.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// rowView.remove(position); //removing from your List
//Toast.makeText(context, "Delete",Toast.LENGTH_LONG).show();
int pid=Integer.parseInt(hldr.pid.getText().toString());
//Toast.makeText(context, "pid"+pid, Toast.LENGTH_LONG).show();
new ShopingCartHelper(context).delProduct(pid);
//PlaceOrder.lv.removeViewAt(position);
notifyDataSetChanged();
}
});
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// // TODO Auto-generated method stub
// cartAdapter.this.pIdz.remove[position];
// Toast.makeText(context, "hi",Toast.LENGTH_LONG).show();
}
});
return rowView;
// TODO Auto-generated method stub
}
}
You can't remove anything from an array - they're always fixed length. Once you've created an array of length 3, that array will always have length 3. And if you want to delete from the listview the array which you are used should be dynamic(Adding & Deleting). So make the pIdz; pNamz;pPrizs;userData into some Modal Object, and prepare the list of Modal Objects and pass it to adapter and make the life easier
You'd be better off with a List, e.g. an ArrayList:
hldr.delete.setTag(position);
hldr.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int position = (int)v.getTag();
list.remove(position);
notifyDataSetChanged();
}
});
First.
You should make a object that stores all your different strings instead of using multiple arrays for each value.
Ej:
class MyClass
{
String id;
String name
String price;
public MyClass(String id, String name, String price)
{
this.id = id;
this.name = name;
this.price = price;
}
}
That way you wouldnt have to delete the position of each of the arrays.
And finally to answer your question, just delete the value of position you want to delete for each of the arrays.
Since they are Array and not ArrayList you will need to recreate it with the correct new dimension (Note it will be much easier with ArrayList).
Then just call notifyDataSetChanged() on your Adapter class.
Hope this helps.
This is my custom list adapter. I want to update the values in table using the update ImageButton in the list. On clicking it, the old values should be shown in a new activity and then the edited value must be stored in the database. However, I am unable to pass an intent inside the onClick() method.
Please suggest me a solution
public class CustomListAdapter extends BaseAdapter implements ListAdapter
{
private ArrayList<String> list = new ArrayList<String>();
private Context context;
OnItemSelectedListener onItemSelectedListener;
public int pos;
String pass,pass2,edit,epass;
public CustomListAdapter(List list, Context context) {
this.list = (ArrayList<String>) list;
this.context = context;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int pos) {
//pass2 = list.toString();
return list.get(pos);
}
//#Override
//public Long getItemId(int pos) {
//
// //just return 0 if your list items do not have an Id variable.
//}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout_custom_list, null);
}
//Handle TextView and display string from your list
final TextView listItemText = (TextView)view.findViewById(R.id.list_item_string);
listItemText.setText(list.get(position));
//Handle buttons and add onClickListeners
ImageButton deleteBtn = (ImageButton)view.findViewById(R.id.delete_btn);
ImageButton editBtn = (ImageButton)view.findViewById(R.id.edit_btn);
//Button addBtn = (Button)view.findViewById(R.id.add_btn);
deleteBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
//do something
list.remove(position);
pass = listItemText.getText().toString();
notifyDataSetChanged();
pass2 = pass.substring(0,pass.indexOf(' '));
System.out.println(pass2);
Moneydb.delete(pass2);
}
});
editBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v2) {
// TODO Auto-generated method stub
edit=listItemText.getText().toString();
epass = listItemText.getText().toString();
edit = epass.substring(0,epass.indexOf(' '));
Moneydb.edit(edit);
}
});
return view;
}
protected Context getContext() {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
//return list.get(position).getId();
return 0;
}
public void clear() {
//CustomListAdapter collection = null;
// TODO Auto-generated method stub
list.clear();
notifyDataSetChanged();
}
I suggest you to assign and ContextMenu to your list view with two MenuItem, Edit and Delete and write associated code outside of adapter
or you can start Activity by :
Intent new_intent = new Intent(v.getRootView().getContext(),edit_activity.class);
new_intent.putExtra("Key","Value");
v.getRootView().getContext().startActivity(new_intent);
i think the first method is best ;)
I fetched data in JSON from web service and then i put data into a custom ListView.
On clicking an item of ListView , I open a new Activity. Now I click on "Submit" Button of this activity I go back to the same ListView ,
When I get back to the ListView, I want to change the text of listitem in which I clicked before
I just want to refresh or re-call the activity when it again comes to listticket.java
Right now data is static . I used web services.
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;
}
}
}
Another layout in when click on ListItem
ticketdetail.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);
}
Make adapter object globally and initialize once within onCreate and inside onResume() notify to your adapter like below:
Delcaration
MyArrayAdapter adapter;
onCreate
adapter = new MyArrayAdapter(this, listArr);
listView.setAdapter(adapter);
onResume()
adapter.notifyDataSetChanged();
Try this, add, clear and remove calls notifyDataSetChanged itself and you dont have to change your adapter everytime you refresh your information, its expensive.
adapter.clear()
for (Object o : object)
adapter.add(o)