I am building an android app where it READ from data Parse.com
I am using a CustomAdapter to display data like this
public class Dining extends Activity {
public Button but12;
public void init12() {
but12 = (Button) findViewById(R.id.button12);
but12.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent toy3 = new Intent(Dining.this, Dining_select.class);
startActivity(toy3);
}
});
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dining);
init12();
}
}
class CustomAdapter extends ParseQueryAdapter<ParseObject> {
public CustomAdapter(Context context) {
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>(){
public ParseQuery create() {
ParseQuery query = new ParseQuery("RestaurantDetail");
/* query.whereEqualTo("Name", true);*/
return query;
}
});
}
#Override
public View getItemView(ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.dining, null);
}
super.getItemView(object, v, parent);
ParseImageView todoImage = (ParseImageView) v.findViewById(R.id.icon);
ParseFile imageFile = object.getParseFile("Logo");
if (imageFile != null) {
todoImage.setParseFile(imageFile);
todoImage.loadInBackground();
}
TextView titleTextView = (TextView) v.findViewById(R.id.textView3);
titleTextView.setText(object.getString("Name"));
return v;
}
}
Then i am also using another class to call the table and display
public class Dining1 extends Dining {
private CustomAdapter urgentTodosAdapter;
private ParseQueryAdapter<ParseObject> mainAdapter;
private ListView dininglist;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.dining1);
mainAdapter = new ParseQueryAdapter<ParseObject>(this, "RestaurantDetail");
urgentTodosAdapter = new CustomAdapter(this);
dininglist = (ListView) findViewById(R.id.dininglistview1);
dininglist.setAdapter(urgentTodosAdapter);
urgentTodosAdapter.loadObjects();
}
}
problem is it does not display any information and i don't understand why.
please help
Related
I am trying out this code i have that uses Parse.com to get restaurant names and put the in a listView.
When you click on one of the names then it takes you to a details page where you can get detail information about the restaurant.
Problem is when i click on the name on the ListView it goes to the details pages but displays nothing.
I am new to android and parse and don't fully understand how it should work.
here is the code in my mainActivity
public class MainActivity extends Activity {
private CustomAdapter urgentTodosAdapter;
private ParseQueryAdapter<ParseObject> mainAdapter;
private ListView listView;
List<ParseObject> Name =new ArrayList<ParseObject>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
mainAdapter = new ParseQueryAdapter<ParseObject>(this,"RestaurantDetail");
urgentTodosAdapter = new CustomAdapter(this);
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(urgentTodosAdapter);
urgentTodosAdapter.loadObjects();
// Binds the Adapter to the ListView
listView.setAdapter(urgentTodosAdapter);
// Capture button clicks on ListView items
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// Send single item click data to SingleItemView Class
Intent random1 = new Intent(MainActivity.this, SingleItemView.class);
if (Name.size() > i)
// Pass data "name" followed by the position
random1.putExtra("Name", Name.get(i).getString("Name"));
// Open SingleItemView.java Activity
startActivity(random1);
}
});
}
}
and my customAdapter class
public class CustomAdapter extends ParseQueryAdapter<ParseObject> {
public CustomAdapter(Context context) {
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("RestaurantDetail");
/* query.whereEqualTo("Name", true);*/
return query;
}
});
}
#Override
public View getItemView(ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.activity_main, null);
}
super.getItemView(object, v, parent);
ParseImageView todoImage = (ParseImageView) v.findViewById(R.id.icon);
ParseFile imageFile = object.getParseFile("Logo");
if (imageFile != null) {
todoImage.setParseFile(imageFile);
todoImage.loadInBackground();
}
TextView titleTextView = (TextView) v.findViewById(R.id.textView3);
titleTextView.setText(object.getString("Name"));
return v;
}
}
and the class that suppose to display the name of the restaurant etc.
#ParseClassName("RestaurantDetail")
public class SingleItemView extends Activity {
// Declare Variables
protected TextView txtname;
String Name;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from SingleItemView.xml
setContentView(R.layout.single_item_view);
txtname = (TextView) findViewById(R.id.name);
// Retrieve data from MainActivity on item click event
Intent random1 = getIntent();
// Get the name
Name = random1.getStringExtra("Name");
// Locate the TextView in singleitemview.xml
// Load the text into the TextView
txtname.setText(Name);
}
}
Please see my comment in the OP's comment section to get some context:
Answer:
In your MainActivity you didn't create a query to add to the adapter. Take a look below and adjust the ParseQuery to your needs:
MainActivity Class
public class MainActivity extends Activity {
private CustomAdapter urgentTodosAdapter;
private ParseQueryAdapter<ParseObject> mainAdapter;
private ListView listView;
List<ParseObject> Name =new ArrayList<ParseObject>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
listView = (ListView) findViewById(R.id.listView1);
//I'm not sure how you initialized your custom adapter - i'll show you how i did it, but yours might work too
urgentTodosAdapter = new urgentTodosAdapter(MainActivity.this, new ArrayList<RestaurantDetail>());
listView.setAdapter(urgentTodosAdapter);
//Here is where you forgot to add your ParseQuery for 'Restaurants'
ParseQuery<RestaurantDetail> query = ParseQuery.getQuery(RestaurantDetail.class);
query.findInBackground(new FindCallback<RestaurantDetail>() {
public void done(List<RestaurantDetail> resutarantList, ParseException e) {
if (e == null) {
if (resutarantList.size() > 0) {
for (int i = 0; i < resutarantList.size(); i++) {
//you forgot to do this - didn't add anything for the adapter to show.
urgentTodosAdapter.add(resutarantList.get(i));
}
} else {
// do something if empty
}
} else {
// do something if null
}
}
});
//This is fine here, but you can also do the same in your adapter class; I'll keep this here and show you where to put it
//in the adapter as well.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// Send single item click data to SingleItemView Class
Intent random1 = new Intent(MainActivity.this, SingleItemView.class);
if (Name.size() > i)
// Pass data "name" followed by the position
random1.putExtra("Name", Name.get(i).getString("Name"));
// Open SingleItemView.java Activity
startActivity(random1);
}
});
}
}
CustomAdapter class:
public class CustomAdapter extends ArrayAdapter<RestaurantDetail> {
private final Context mContext;
private List<RestaurantDetail> restrauants;
public CustomAdapter(Context context, List<RestaurantDetail> objects) {
super(context, R.layout.include_restaurants, objects);
this.mContext = context;
this.restrauants = objects;
}
public View getView(final int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
v = mLayoutInflater.inflate(R.layout.include_restaurants, null);
}
ParseImageView todoImage = (ParseImageView) v.findViewById(R.id.icon);
ParseFile imageFile = object.getParseFile("Logo");
if (imageFile != null) {
todoImage.setParseFile(imageFile);
todoImage.loadInBackground();
}
TextView titleTextView = (TextView) v.findViewById(R.id.textView3);
titleTextView.setText(object.getString("Name"));
//this is also where you can handle to onClick stuff
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
return v;
}
}
Initialize your parse class: this is also where you can put your getters/setters.
#ParseClassName("YourClassNameInYourDBHere")
public class ResuaurantDetail(your class here) extends ParseObject
{
}
I have a list view populated threw an SQlitedatabase but I need to pass to a detail activity from the list view. The problem is in passing the details from the listview activity to the detail activity because when I click the detail activity it gives me blank edit texts
Here is my listview activity:
public class consulter_note extends Activity implements AdapterView.OnItemClickListener{
ListView list;
SQLiteDatabase sqLiteDatabase;
DataBaseOperationstwo dataBaseOperationstwo;
Cursor cursor;
ListDataAdapter listDataAdapter;
String titre,objet;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consulter_note);
list = (ListView) findViewById(R.id.listView);
listDataAdapter = new ListDataAdapter(getApplicationContext(),R.layout.notelist_row);
list.setAdapter(listDataAdapter);
list.setOnItemClickListener(this);
dataBaseOperationstwo = new DataBaseOperationstwo(getApplicationContext());
sqLiteDatabase = dataBaseOperationstwo.getReadableDatabase();
cursor = dataBaseOperationstwo.getInformations(sqLiteDatabase);
if (cursor.moveToFirst())
{
do
{
titre = cursor.getString(0);
objet = cursor.getString(1);
DataProvider dataProvider = new DataProvider(titre,objet);
listDataAdapter.add(dataProvider);
}while (cursor.moveToNext());
}
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(this, note_details.class);
startActivity(intent);
intent.putExtra("titre", titre);
intent.putExtra("objet", objet);
}
}
And here is my array adapter:
public class ListDataAdapter extends ArrayAdapter{
List list = new ArrayList();
public ListDataAdapter(Context context, int resource) {
super(context, resource);
}
static class LayoutHandler
{
TextView TITRE,OBJET;
}
#Override
public void add(Object object) {
super.add(object);
list.add(object);
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutHandler layoutHandler;
if (row == null)
{
LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.notelist_row,parent,false);
layoutHandler = new LayoutHandler();
layoutHandler.TITRE = (TextView) row.findViewById(R.id.titredemo);
layoutHandler.OBJET = (TextView) row.findViewById(R.id.objetdemo);
row.setTag(layoutHandler);
}
else
{
layoutHandler = (LayoutHandler) row.getTag();
}
DataProvider dataProvider = (DataProvider) this.getItem(position);
layoutHandler.TITRE.setText(dataProvider.getTitre());
layoutHandler.OBJET.setText(dataProvider.getObjet());
return row;
}
}
The data provider class used in the array adapter:
public class DataProvider {
private String titre,objet;
public DataProvider(String titre,String objet)
{
this.titre = titre;
this.objet = objet;
}
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
public String getObjet() {
return objet;
}
public void setObjet(String objet) {
this.objet = objet;
}
}
And finally my details activity. I'm only interested in the intent part; the rest has nothing to do with my problem:
public class note_details extends Activity {
ImageButton Del;
EditText PASSTITRE,USEROBJET;
String Passtitre,Userobjet;
DataBaseOperationstwo DOP;
Context CTX = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent =getIntent();
if(intent != null)
{
String objet = intent.getStringExtra("objet");
String titre= intent.getStringExtra("titre");
PASSTITRE.setText(objet);
USEROBJET.setText(objet);
}
setContentView(R.layout.activity_note_details);
Del = (ImageButton) findViewById(R.id.suppnote);
PASSTITRE = (EditText) findViewById(R.id.titree);
USEROBJET = (EditText) findViewById(R.id.objett);
Del.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Passtitre = PASSTITRE.getText().toString();
Userobjet = USEROBJET.getText().toString();
DOP = new DataBaseOperationstwo(CTX);
DOP.deleteNote(DOP,Passtitre,Userobjet);
Toast.makeText(getBaseContext(),"note supprimé",Toast.LENGTH_LONG).show();
finish();
}
});
}
public void liste(View v)
{
Intent i = new Intent(this, consulter_note.class);
startActivity(i);
}
public void supprimer(View v)
{
}
}
My logcat doesn’t show any errors but the details activity shows with empty edittexts.
You should first add extras to the Intent and then fire it:
Intent intent = new Intent(this, note_details.class);
intent.putExtra("titre", titre);
intent.putExtra("objet", objet);
startActivity(intent);
Another thing worth mentioning is that you should avoid doing DB queries on the main thread, as it will slow down your app. Use Loaders, or just run queries on worker threads.
My project includes an "accept/deny incoming data" window that on "accept" should add the incoming data dynamically to a listview and the database that the listview gets the data from. My listadapter is an inner class.
My code in the main class relating to the populating of the listview:
public class MainActivity extends Activity {
private List<Assignment> allDeliveries= new ArrayList<Assignment>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateDeliveryList();
populateListView();
registerClickCallBack();
final MySQLiteHelper db = new MySQLiteHelper(this);
accept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RelativeLayout newdeliverylayout= (RelativeLayout) findViewById(R.id.newdeliverylayout);
allDeliveries.add(incomingAssignment);
db.addAssignment(incomingAssignment);
MyListAdapter adapter = new MyListAdapter();
adapter.notifyDataSetChanged();
}
});
deny.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RelativeLayout newdeliverylayout= (RelativeLayout) findViewById(R.id.newdeliverylayout);
newdeliverylayout.setVisibility(RelativeLayout.GONE);
}
});
private void populateDeliveryList() {
MySQLiteHelper db = new MySQLiteHelper(this);
List<Assignment> list = db.getAllAssignments();
for (int i = 0; i < list.size();i++)
{
allDeliveries.add(list.get(i));
}
}
private void populateListView() {
ArrayAdapter<Assignment> adapter = new MyListAdapter();
ListView list = (ListView) findViewById(R.id.deliveriesListView);
list.setAdapter(adapter);
}
}
This is my inner class, the listadapter:
private class MyListAdapter extends ArrayAdapter<Assignment> {
public MyListAdapter() {
super(MainActivity.this, R.layout.item_view, allDeliveries);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if (itemView == null) {
itemView = getLayoutInflater().inflate(R.layout.item_view, parent, false);
}
Assignment nyDelivery = allDeliveries.get(position);
TextView adressText = (TextView) itemView.findViewById(R.id.item_adressView);
adressText.setText(nyDelivery.getAdress());
TextView zipText = (TextView) itemView.findViewById(R.id.item_zipcodePlaceView);
zipText.setText(nyDelivery.getZipcode());
TextView companyText = (TextView) itemView.findViewById(R.id.item_companyView);
companyText.setText(nyDelivery.getSenderreceiver());
TextView typeText = (TextView) itemView.findViewById(R.id.item_driveTypeView);
typeText.setText(nyDelivery.getType() + nyDelivery.getID());
return itemView;
}
}
}
The code in "accept" seems to do nothing except adding the incoming assignment to the database.
It is a simple change of declaring MyListAdapter in your MainActivity and instantiate it once in the populateListView,
public class MainActivity extends Activity {
private List<Assignment> allDeliveries= new ArrayList<Assignment>();
MyListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateDeliveryList();
populateListView();
registerClickCallBack();
final MySQLiteHelper db = new MySQLiteHelper(this);
accept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RelativeLayout newdeliverylayout= (RelativeLayout) findViewById(R.id.newdeliverylayout);
allDeliveries.add(incomingAssignment);
db.addAssignment(incomingAssignment);
adapter.notifyDataSetChanged();
}
});
deny.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RelativeLayout newdeliverylayout= (RelativeLayout) findViewById(R.id.newdeliverylayout);
newdeliverylayout.setVisibility(RelativeLayout.GONE);
}
});
private void populateDeliveryList() {
MySQLiteHelper db = new MySQLiteHelper(this);
List<Assignment> list = db.getAllAssignments();
for (int i = 0; i < list.size();i++)
{
allDeliveries.add(list.get(i));
}
}
private void populateListView() {
adapter = new MyListAdapter();
ListView list = (ListView) findViewById(R.id.deliveriesListView);
list.setAdapter(adapter);
}
}
I have a problem with click on image in item in ListView. When I click I want to show layout which is gone. This is my code:
public class MyActualOffers extends BaseActivity {
private IResponse iResponse = null;
private ListView actualOffersList;
private ActualOffersListAdapter actualOffersAdapter;
private ArrayList<Offers> actualOffersFromJson;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_actual_offers);
actualOffersFromJson = new ArrayList<Offers>();
actualOffersList = (ListView) findViewById(R.id.actualOffersList);
iResponse = new IResponse() {
#Override
public void onResponse(JSONObject jObject) {
// messageUser = new User();
// messageUser.parseJsonResponse(jObject);
// usersMessages.add(messageUser);
// new DownloadImageTask(profileP)
// .execute("http://"+messageUser.getAvatarURL());
//
// messagesListView.refreshDrawableState();
// adapter.notifyDataSetChanged();
// adapter.notifyDataSetInvalidated();
}
#Override
public void onResponse(JSONArray jArray) {
try {
for (int i = 0; i < 3; i++) {
JSONObject messageJSON = (JSONObject)jArray.get(i);
Offers offer = new Offers();
offer.parseJsonResponse(messageJSON);
actualOffersFromJson.add(offer);
}
}catch (JSONException e) {
e.printStackTrace();
}
actualOffersAdapter = new ActualOffersListAdapter(getApplicationContext(), actualOffersFromJson);
actualOffersList.setAdapter(actualOffersAdapter);
// adapter = new MessagesListAdapter(getApplicationContext(), myMessagesList, usersMessages);
// messagesListView.setAdapter(adapter);
}
#Override
public void onError(JSONObject jObject) {
ErrorObject error = new ErrorObject();
error.parseJsonResponse(jObject);
error.showErrorDialog(MyActualOffers.this);
}
};
getActualMyOffers();
}
private void getActualMyOffers(){
SharedPreferencesData sharedData = new SharedPreferencesData();
String url = ConnectionParams.URL_OFFERS_FETCH_CURRENT_USER_OFFERS.replace("{0}", ""+"get");
String token = "?auth_token="+sharedData.getTokenData(getBaseContext());
connection.get(url + token + "&state=active", iResponse);
}
private class ActualOffersListAdapter extends BaseAdapter {
private Context context;
private ArrayList<Offers> offersList;
private LayoutInflater inflater;
private ViewHolder holder;
boolean isExpand = false;
public ActualOffersListAdapter(Context context, ArrayList<Offers> offersList) {
this.context = context;
this.offersList = offersList;
inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return offersList.size();
}
#Override
public Object getItem(int position) {
return offersList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(
R.layout.actual_offers_list_item, null);
holder = new ViewHolder();
holder.cities = (TextViewWithImage) convertView.findViewById(R.id.actualOffersFromCityTXT);
holder.date = (TextView) convertView.findViewById(R.id.actualOffersCalendarTXT);
holder.type = (TextView) convertView.findViewById(R.id.actualOffersTripTypeTXT);
holder.shipment = (TextView) convertView.findViewById(R.id.actualOffersShipmentTypeTXT);
holder.transport = (TextView) convertView.findViewById(R.id.actualOffersTransportTypeTXT);
holder.deleteOffer = (TextView) convertView.findViewById(R.id.actualOffersDeleteTXT);
holder.editOffer = (TextView) convertView.findViewById(R.id.actualOffersEditOfferTXT);
holder.addSimilar = (TextView) convertView.findViewById(R.id.actualOffersAddSimilarTXT);
holder.addOpposite = (TextView) convertView.findViewById(R.id.actualOffersAddOppositeTXT);
holder.infoIcon = (ImageView) convertView.findViewById(R.id.actualOffersInfoICON);
holder.shipmentIcon = (ImageView) convertView.findViewById(R.id.actualOffersShipmentTypeICON);
holder.transportIcon = (ImageView) convertView.findViewById(R.id.actualOffersTransportTypeICON);
holder.typeIcon = (ImageView) convertView.findViewById(R.id.actualOffersTripTypeICON);
holder.expandIcon = (ImageView) convertView.findViewById(R.id.expandIcon);
holder.actualOffersExpandLayout = (RelativeLayout) convertView.findViewById(R.id.actualOffersExpandLayout);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.cities.setText(offersList.get(position).getStart() + " [img src=ic_in_text_arrow/] " + offersList.get(position).getDestination());
holder.date.setText(offersList.get(position).getCreatedAt());
if(offersList.get(position).getFrequency().equals("once")){
holder.typeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_in_text_once));
}else{
holder.typeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_in_text_infinity));
}
holder.type.setText(offersList.get(position).getType());
holder.shipmentIcon.setImageDrawable(ShipmentTypeEnum.setIconForShipmentType(ShipmentTypeEnum.fromString(offersList.get(position).getShipmentType()), getApplicationContext()));
holder.transportIcon.setImageDrawable(TransportTypeEnum.setIconForTransportType(TransportTypeEnum.fromString(offersList.get(position).getTransportType()), getApplicationContext()));
holder.deleteOffer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
holder.editOffer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
holder.addSimilar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
holder.addOpposite.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
holder.expandIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(isExpand){
holder.actualOffersExpandLayout.setVisibility(View.INVISIBLE);
isExpand = false;
}else{
holder.actualOffersExpandLayout.setVisibility(View.VISIBLE);
isExpand = true;
}
}
});
holder.infoIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
return convertView;
}
}
public static class ViewHolder {
public TextViewWithImage cities;
public TextView date;
public TextView type;
public TextView shipment;
public TextView transport;
public TextView deleteOffer;
public TextView editOffer;
public TextView addSimilar;
public TextView addOpposite;
public ImageView infoIcon;
public ImageView shipmentIcon;
public ImageView transportIcon;
public ImageView typeIcon;
public ImageView expandIcon;
public RelativeLayout actualOffersExpandLayout;
}
}
No when I click on holder.expandIcon in first item, expand layout show in last item of list. How can I create list with my item and properly working click on image in every item?
You are expanding the last item in the list because that was the last view retrieved by getView. The way the code is written now, there is only one isExpand value.
So you need to (a) add isExpand on the ViewHolder, and (b) use the ViewHolder attached to the View that was passed in the event handler. Like this:
holder.expandIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ViewHolder vh = (ViewHolder)v.getTag();
if(vh.isExpand){
vh.actualOffersExpandLayout.setVisibility(View.INVISIBLE);
vh.isExpand = false;
}else{
vh.actualOffersExpandLayout.setVisibility(View.VISIBLE);
vh.isExpand = true;
}
}
});
I am making a sectional listview in which to section first is pending request list and second is already friend there are two button accept and reject in first section of list view.
When I click on accept hit server and change stautus and now my List should be update and first section accepted list should showing in friendlist in second section of listview.
I am using following code:-
public class EntryAdapter extends ArrayAdapter<Item> {
private Context context;
private List<Item> items;
private LayoutInflater objlayoutinflator;
private PostJobImageLoader objimageLoader;
private ConnectionFriendListModle objmodle=null;
public EntryAdapter(Context context,List<Item> items) {
super(context, 0, items);
this.context = context;
this.items = items;
objlayoutinflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
objimageLoader = new PostJobImageLoader(context.getApplicationContext());
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View myview = convertView;
final Item objitem = items.get(position);
if (objitem != null) {
if (objitem.isSection()) {
SectionItem objsection = (SectionItem) objitem;
myview = objlayoutinflator.inflate(R.layout.listviewsection,
null);
myview.setOnClickListener(null);
myview.setOnLongClickListener(null);
myview.setLongClickable(false);
final TextView sectionView = (TextView) myview
.findViewById(R.id.txtsection);
sectionView.setText(objsection.getTitle());
} else {
objmodle = (ConnectionFriendListModle) objitem;
myview = objlayoutinflator.inflate(R.layout.connectionlistrow,
null);
final TextView title = (TextView) myview
.findViewById(R.id.jobtitleinjobbidalert);
final TextView subtitle = (TextView) myview
.findViewById(R.id.jobsubtitle);
final ImageView objimageview = (ImageView) myview
.findViewById(R.id.user_image);
final Button objaccept = (Button) myview
.findViewById(R.id.btnaccept);
final Button objreject = (Button) myview
.findViewById(R.id.btnreject);
if (objmodle.getStatus().equalsIgnoreCase("pending")) {
objaccept.setVisibility(View.VISIBLE);
objreject.setVisibility(View.VISIBLE);
title.setText(objmodle.getUsername());
subtitle.setText(objmodle.getName());
String url = objmodle.getPicture();
objimageLoader.DisplayImage(AppConstants.IMAGE_BASE_URL
+ url, objimageview);
} else {
objaccept.setVisibility(View.INVISIBLE);
objreject.setVisibility(View.INVISIBLE);
title.setText(objmodle.getUsername());
subtitle.setText(objmodle.getName());
String url = objmodle.getPicture();
objimageLoader.DisplayImage(AppConstants.IMAGE_BASE_URL+url, objimageview);
}
objaccept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new AcceptFriendRequest().execute(objmodle.getId(),"accepted");
}
});
objreject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
}
});
}
}
return myview;
}
private class AcceptFriendRequest extends AsyncTask<String,Void,String>
{
ProgressDialog objprogress = new ProgressDialog(EntryAdapter.this.context);
AppRequestHandler objApprequest = new AppRequestHandler();
String objresponce="";
#Override
protected void onPreExecute() {
objprogress.setMessage("Please Wait While Loading...");
objprogress.show();
}
#Override
protected String doInBackground(String... params) {
objresponce = objApprequest.acceptRequest(params[0],params[1]);
return objresponce;
}
#Override
protected void onPostExecute(String result) {
if(objprogress.isShowing())
{
objprogress.dismiss();
}
if(result.equals("0"))
{
SharedPreferences myPrefs = EntryAdapter.this.context.getSharedPreferences(
AppConstants.MYPREF, EntryAdapter.this.context.MODE_WORLD_READABLE);
String userid = myPrefs.getString(AppConstants.USER_ID, "");
//but when controll reach this line not execute this asynctask and niether update listview
new GetAllConnectionDetail().equals("86");
}
}
}
private class GetAllConnectionDetail extends AsyncTask<String,Void,List<Item>>
{
ProgressDialog objprogress = new ProgressDialog(EntryAdapter.this.context);
AppRequestHandler objApprequest = new AppRequestHandler();
List<Item> objlistitem=null;
#Override
protected void onPreExecute() {
objprogress.setMessage("Please Wait While Loading...");
objprogress.show();
}
#Override
protected List<Item> doInBackground(String... params) {
objlistitem = objApprequest.connectionDetails(params[0]);
return objlistitem;
}
#Override
protected void onPostExecute(List<Item> result) {
if(objprogress.isShowing())
{
objprogress.dismiss();
}
items.clear();
items.addAll(result);
notifyDataSetChanged();
}
}
}
Is am going right way or wrong please any one help me why it is not working...
You have to start your GetAllConnectionDetail task by calling its execute method, seems you don't do that.