I've an error in my simpleAdapter on 'map' and can't resolve it. I've created a LinkedHashMap through a json file.
See screenshot below. I assume it's correct. This screenshot is only for seeing the content of the array.
See my code below:
import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.LinkedHashMap;
public class BlogFragment extends Fragment {
View myView;
ArrayList<String> lists = new ArrayList<>();
ListView lv = (ListView) myView.findViewById(R.id.listView);
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.blog_layout, container, false);
new AsyncTaskParseJson().execute();
return myView;
}
public class AsyncTaskParseJson extends AsyncTask<LinkedHashMap, LinkedHashMap, LinkedHashMap> {
String url = "myUrl"; // Link to json file
JSONArray dataJsonArr = null;
ProgressDialog dialog;
#Override
protected void onPreExecute() {
dialog = ProgressDialog.show(getActivity(), "", "Loading blog ...");
}
#Override
protected LinkedHashMap<Integer, ArrayList<String>> doInBackground(LinkedHashMap... params) {
LinkedHashMap<Integer, ArrayList<String>> map = new LinkedHashMap<>();
try {
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
dataJsonArr = json.getJSONArray("blog");
for (int i = dataJsonArr.length()-1; i >= 0 ; i--) {
JSONObject c = dataJsonArr.getJSONObject(i);
String afb = c.getString("afbeelding");
String tt = c.getString("titel");
String inh = c.getString("inhoud");
lists = new ArrayList<>();
lists.add(tt);
lists.add(afb);
lists.add(inh);
map.put(i,lists);
}
} catch (JSONException e) {
e.printStackTrace();
}
return map;
}
#Override
protected void onPostExecute(LinkedHashMap map) {
dialog.dismiss();
String[] from = new String[]{"6", "5", "4", "3", "2", "1"};
int[] to = new int[]{R.id.textView, R.id.textView2, R.id.textView3};
//Map<String, ArrayList<String>> map1 = new LinkedHashMap<>(map);
SimpleAdapter simpleAdapter;
simpleAdapter = new SimpleAdapter(getActivity(), map, R.layout.blog_layout, from, to); // <<< **I get an error on 'map'**
lv.setAdapter(simpleAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(), Detail.class);
i.putExtra("string", Long.toString(id));
startActivity(i);
}
});
}}}
I already tried to convert LinkedHashMap to Map but it didn't resolve the issue.
Can someone help me, please?
Thank you!
Related
I'm trying to create a simple news application,I am able to display data in the listview, But I want to display it in grid format.I am not getting any idea how to achieve that. Please support
Updted Code
package com.journaldev.androidrssfeedtutorial;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class RSSFeedActivity extends AppCompatActivity {
private ProgressBar pDialog;
ArrayList<HashMap<String, String>> rssItemList = new ArrayList<>();
RSSParser rssParser = new RSSParser();
Toolbar toolbar;
GridView gridView;
List<RSSItem> rssItems = new ArrayList<>();
private static String TAG_TITLE = "title";
private static String TAG_LINK = "link";
private static String TAG_DESCRIPTION = "description";
private static String TAG_PUB_DATE = "pubDate";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rss_feed);
String rss_link = getIntent().getStringExtra("rssLink");
new LoadRSSFeedItems().execute(rss_link);
/* ListView lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent in = new Intent(getApplicationContext(),
MainActivity.class);
String page_url = ((TextView)
view.findViewById(R.id.page_url)).getText().toString().trim();
in.putExtra("url", page_url);
startActivity(in);
}
});*/
}
public class LoadRSSFeedItems extends AsyncTask<String, String,
String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressBar(RSSFeedActivity.this, null,
android.R.attr.progressBarStyleLarge);
RelativeLayout relativeLayout = findViewById(R.id.relativeLayout);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
pDialog.setLayoutParams(lp);
pDialog.setVisibility(View.VISIBLE);
relativeLayout.addView(pDialog);
}
#Override
protected String doInBackground(String... args) {
// rss link url
String rss_url = args[0];
// list of rss items
rssItems = rssParser.getRSSFeedItems(rss_url);
// looping through each item
for (RSSItem item : rssItems) {
// creating new HashMap
if (item.link.toString().equals(""))
break;
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
String givenDateString = item.pubdate.trim();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy
HH:mm:ss Z");
try {
Date mDate = sdf.parse(givenDateString);
SimpleDateFormat sdf2 = new SimpleDateFormat("EEEE, dd MMMM
yyyy - hh:mm a", Locale.US);
item.pubdate = sdf2.format(mDate);
} catch (ParseException e) {
e.printStackTrace();
}
map.put(TAG_TITLE, item.title);
map.put(TAG_LINK, item.link);
map.put(TAG_DESCRIPTION, item.description);
map.put(TAG_PUB_DATE, item.pubdate); // If you want parse the
date
// adding HashList to ArrayList
rssItemList.add(map);
}
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/* ListAdapter adapter = new SimpleAdapter( //Old code
RSSFeedActivity.this,
rssItemList, R.layout.rss_item_list_row,
new String[]{TAG_LINK, TAG_TITLE,
TAG_DESCRIPTION,TAG_PUB_DATE},
new int[]{R.id.page_url, R.id.title,
R.id.description, R.id.pub_date});
// updating listview
setListAdapter(adapter);*/
RecyclerView recyclerView = (RecyclerView)
findViewById(R.id.recyclerView);
// set a GridLayoutManager with default vertical orientation
and 2 number of columns
GridLayoutManager gridLayoutManager = new
GridLayoutManager(getApplicationContext(), 2);
recyclerView.setLayoutManager(gridLayoutManager); // set
LayoutManager to RecyclerView
// call the constructor of CustomAdapter to send the
reference and data to Adapter
CustomAdapter customAdapter = new
CustomAdapter(RSSFeedActivity.this, rssItemList, new String[]
{TAG_LINK, TAG_TITLE, TAG_DESCRIPTION,TAG_PUB_DATE});
recyclerView.setAdapter(customAdapter);
}
});
return null;
}
protected void onPostExecute(String args) {
pDialog.setVisibility(View.GONE);
}
}
}
Custom Adapter class:
public class CustomAdapter extends
RecyclerView.Adapter<CustomAdapter.MyViewHolder> {
ArrayList rssItemList;
Context context;
public CustomAdapter(Context context, ArrayList rssItemList,String[]
from) {
this.context = context;
this.rssItemList = rssItemList;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int
viewType) {
// infalte the item Layout
View v =
LayoutInflater.from(parent.getContext()).inflate(R.layout.gridview_row,
parent, false);
// set the view's size, margins, paddings and layout parameters
MyViewHolder vh = new MyViewHolder(v); // pass the view to View
Holder
return vh;
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position)
{
holder.name.setText(rssItemList.get(position)); //Showing error
holder.image.setText(rssItemList.get(position)); //Showing error
}
#Override
public int getItemCount() {
return rssItemList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
// init the item view's
TextView name;
TextView image;
public MyViewHolder(View itemView) {
super(itemView);
// get the reference of item view's
name = (TextView)
itemView.findViewById(R.id.android_gridview_text1);
image = (TextView)
itemView.findViewById(R.id.android_gridview_text2);
}
}
}
No i am facing one problem.Not able to pass data to custom adapter.Pls help me to solve this issue.
I want to display what my array list value is. So, I want to loop with the size of array list as the limit. But after I add some value through a function, and want to get the size of it, it always 0. I still newbie in android programming. I had search in google, but still confused and not understand what the problem is. Thanks for you guys help
I had tried to set through global variable, but it's not work
Here is my activity file
package bobby.irawan.aticket;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;
public class DetailPromoActivity extends AppCompatActivity {
private ListView listView;
private TextView nama_detail_promo_tv;
private String nama_detail_promo;
private DetailPromoAdapter adapter;
private int counter_header=0, counter_promo = 0;
private View layout_kupon;
private int id_link_promo;
private RequestQueue requestQueue;
private String url = "192.168.11.134:8000";
private TextView header_promo, kupon_promo, notif_promo;
private ArrayList<DetailPromo> detailPromos;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_promo);
View view = findViewById(R.id.layout_kupon);
header_promo = view.findViewById(R.id.header_promo_tv);
kupon_promo = view.findViewById(R.id.kode_promo_tv);
id_link_promo = (int) getIntent().getSerializableExtra("id_promo");
nama_detail_promo = (String) getIntent().getSerializableExtra("nama_promo");
String nama_ota = (String) getIntent().getSerializableExtra("nama_ota");
listView = findViewById(R.id.lv_detpro);
layout_kupon = findViewById(R.id.layout_kupon);
header_promo = layout_kupon.findViewById(R.id.header_promo_tv);
kupon_promo = layout_kupon.findViewById(R.id.kode_promo_tv);
notif_promo = layout_kupon.findViewById(R.id.notif_promo_tv);
requestQueue = Volley.newRequestQueue(this);
nama_detail_promo_tv = findViewById(R.id.nama_detail_promo);
nama_detail_promo_tv.setText(nama_detail_promo);
setDetailPromotoClass(id_link_promo);
adapter = new DetailPromoAdapter(detailPromos,this);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle("Promo "+nama_ota);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
//Set kupon
System.out.println("Size detpro "+counter_header+" "+counter_promo);
if(counter_header == 0 && counter_promo == 0){
notif_promo.setVisibility(View.VISIBLE);
header_promo.setVisibility(View.GONE);
kupon_promo.setVisibility(View.GONE);
System.out.println("Masuk sini");
}
else if(counter_header == 0){
header_promo.setText("PROMO PESAWAT");
}
else{
kupon_promo.setText("Tidak perlu");
}
}
class DetailPromoAdapter extends BaseAdapter {
private List<DetailPromo> detailPromo;
private Context context;
public DetailPromoAdapter(List<DetailPromo> detailPromo, Context context) {
this.detailPromo = detailPromo;
this.context = context;
}
#Override
public int getCount() {
System.out.println("Detail promo size"+detailPromo.size());
return detailPromo.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = getLayoutInflater().inflate(R.layout.detail_promo_adapter, parent, false);
TextView nama_detail_promo = convertView.findViewById(R.id.isi_detail_promo);
if(detailPromo.get(position).getDetpro_role().equals("detail_promo")){
nama_detail_promo.setText(detailPromo.get(position).getDetpro_list());
}
return convertView;
}
}
public void setDetailPromotoClass(int id_linkpro){
detailPromos = new ArrayList<DetailPromo>();
String url_promo = "http://"+url+"/detail_promo/"+id_linkpro;
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url_promo, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("data");
for(int i=0; i<jsonArray.length(); i++){
JSONObject data_promo = jsonArray.getJSONObject(i);
int id_detpro = data_promo.getInt("id");
int id_promo = data_promo.getInt("promo_id");
int id_linkpro = data_promo.getInt("linkpro_id");
String detpro_list = data_promo.getString("detpro_list");
String detpro_role = data_promo.getString("detpro_role");
detailPromos.add(new DetailPromo(id_detpro,id_promo,id_linkpro,detpro_list,detpro_role));
System.out.println("Data promo yang diklik "+id_promo+" "+id_linkpro+" "+detpro_list+" "+detpro_role);
adapter.notifyDataSetChanged();
if(detpro_role.equals("header_promo")){
header_promo.setText(detailPromos.get(i).detpro_list);
System.out.println("Ada header");
counter_header++;
}
if(detpro_role.equals("kode_promo")){
System.out.println("Ada kupon");
kupon_promo.setText(detailPromos.get(i).detpro_list);
counter_promo++;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
requestQueue.add(request);
}
}
I'm trying to fill make the data show in my Listview, however when i click on the fragment there is nothing on the list.
I've tried move the setAdapter inside the loop but it did not work.
I'm running out of ideas about how to make it work
Has anybody tried to fill an custom adapter with fragments before???
This is my Custom Adapter
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/**
* Created by calvi on 22/05/2018.
*/
public class MyListAdapter extends ArrayAdapter<User> {
List<User> userList;
Context context;
int resource;
public MyListAdapter(#NonNull Context context, #LayoutRes int resource, List<User> userList) {
super(context, resource, userList);
this.context = context;
this.resource = resource;
this.userList = userList;
}
#NonNull
#Override
public View getView(final int position, #Nullable View convertView, #NonNull ViewGroup parent) {
//And for this we need a layoutinflater
LayoutInflater layoutInflater = LayoutInflater.from(context);
Log.d("listando", "Antes do inflater");
//getting the view
View view = layoutInflater.inflate(resource, null, false);
Log.d("listando", "Depois do inflater");
//getting the view elements of the list from the view
TextView textViewName = view.findViewById(R.id.list_row);
Log.d("listando", "Depois de pegar o textview");
//getting the hero of the specified position
User user = userList.get(position);
Log.d("listando", "Depois de pegar o get pisition");
//adding values to the list item
textViewName.setText(user.getName());
Log.d("listando", "Depois de setar o name");
//finally returning the view
return view;
}
}
And this is my Fragment which are taking data from firebase and populating it on the adapter
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.GenericTypeIndicator;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class UserMessageListFragment extends Fragment {
private ProgressDialog progressDialog;
private final String TAG = "UsersMessageLis";
private ArrayList<String> arrayList = new ArrayList<>();
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
private int totalUsers = 0;
private ListView listView;
private TextView noUsersText;
private List<User> userList = new ArrayList<>();
public static UserMessageListFragment newInstance() {
return new UserMessageListFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_user_message_list, container, false);
listView = view.findViewById(R.id.usersListListView);
noUsersText = view.findViewById(R.id.noUsersText);
final DatabaseReference refMessages = FirebaseDatabase.getInstance().getReference();
final DatabaseReference ref= FirebaseDatabase.getInstance().getReference().child("usuarios");
refMessages.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.getKey().contains(UserDetails.username+ "_")) {
final String[] userChatWithId = dataSnapshot.getKey().split(UserDetails.username+"_");
ref.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.getKey().equals(userChatWithId[1])) {
GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {};
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator);
String name = map.get("name").toString();
String username = map.get("username").toString();
String status = map.get("status").toString();
String city = map.get("city").toString();
Log.d("listando", name);
Log.d("listando", username);
Log.d("listando", status);
Log.d("listando", city);
User newUser = new User(username, status, city, name);
Log.d("Listando", newUser.toString());
userList.add(newUser);
//// usersList.setAdapter(new ArrayAdapter<>(getContext(), R.layout.my_list, arrayList));
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
MyListAdapter adapter = new MyListAdapter(getContext(), R.layout.my_list, userList);
//attaching adapter to the listview
listView.setAdapter(adapter);
// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// #Override
// public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// UserDetails.chatWithId = arrayList.get(position);
// startActivity(new Intent(getContext(), Chat.class));
// }
// });
return view;
}
// public void doOnSuccess(String response) {
//
// try {
// JSONObject object = new JSONObject(response);
// Iterator iterator = object.keys();
// String key = "";
//
// while(iterator.hasNext()) {
// key = iterator.next().toString();
//
// if(! key.equals(UserDetails.username)) {
// arrayList.add(key);
// }
// totalUsers++;
// }
//
// } catch (JSONException e) {
// e.printStackTrace();
// }
//
// checkIfThereIsAnUser(totalUsers);
// }
// public void checkIfThereIsAnUser(int totalUsers) {
//
//
// if(totalUsers <=1){
// noUsersText.setVisibility(View.VISIBLE);
// usersList.setVisibility(View.GONE);
// }
// else{
// noUsersText.setVisibility(View.GONE);
// usersList.setVisibility(View.VISIBLE);
// usersList.setAdapter(new ArrayAdapter<>(getContext(), R.layout.my_list, arrayList));
// }
// progressDialog.dismiss();
// }
}
What i have noticed is that the logs inside the adapter are not showing
When you create adapter
MyListAdapter adapter = new MyListAdapter(getContext(), R.layout.my_list, userList);
the userList is empty. So when you add an item to userList, you have to adapter.notifyDataSetChange() to update your adapter
Try refMessages.addChildEventListener(getActivity(),new ChildEventListener() {......}
Do this in every listeners if they are in fragments.
In case of an Activity you don't need to do this.
I checked all the previous questions regarding this issue, but none of them are helpful to me.
I am trying to open new activity in my listview onItemClickListener but it is not opening the new activity. In the android monitor, it shows
"D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN".
The onItemClickListener is not responding when I click that item of my listview... Is it possible to open?
The activity is successfully running, but I am unable to listen for list click events.
How to correct this?
Here is my class :
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.banyan.simtaa_erp.R;
import com.example.banyan.simtaa_erp.activity.Activity_Add_Enquiry;
import com.example.banyan.simtaa_erp.activity.Activity_Enquiry_Description;
import com.example.banyan.simtaa_erp.adapter.Adapter_Enquiry_List;
import com.example.banyan.simtaa_erp.global.App_Config;
import com.example.banyan.simtaa_erp.global.Session_Manager;
import com.sdsmdg.tastytoast.TastyToast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import dmax.dialog.SpotsDialog;
import static com.willy.ratingbar.BaseRatingBar.TAG;
public class Fragment_Enquiry_List extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
public Fragment_Enquiry_List() {
}
private FloatingActionButton fab_enquiry;
String str_user_name, str_user_id,str_select_task_id;
private ProgressDialog pDialog;
private SpotsDialog dialog_load_more;
public static RequestQueue queue;
Session_Manager session;
private SwipeRefreshLayout enquiry_list_swipe_refresh_layout;
private ListView enquiry_listView;
public static final String TAG_ID= "id";
public static final String TAG_CUSTOMER_ID = "cus_id";
public static final String TAG_IMAGE_ENQUIRY = "image";
public static final String TAG_DESCRIPTION = "description";
public static final String TAG_DATE_ENQUIRY = "date";
public static final String TAG_PROJECT_STATUS = "project_status";
public static final String TAG_CREATED_USERID = "created_userid";
public static final String TAG_CREATED_USERROLE = "created_userrole";
public static final String TAG_CREATED_DATETIME = "created_datetime";
public static final String TAG_CUSTOMER_DETAILS = "customer_details";
int int_starting_item_no = 0, int_last_item_no = 0, int_load_more_count = 100;
public Adapter_Enquiry_List Adapter;
static ArrayList<HashMap<String, String>> enquiry_list;
HashMap<String, String> params = new HashMap<String, String>();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_enquiry_list, container, false);
session = new Session_Manager(getActivity());
session.checkLogin();
HashMap<String, String> user = session.getUserDetails();
str_user_id = user.get(Session_Manager.KEY_USER_ID);
str_user_name = user.get(Session_Manager.KEY_USER_NAME);
System.out.println("USER ID from Session ::::" + str_user_id);
System.out.println("USER NAME from Session ::::" + str_user_name);
enquiry_listView = (ListView) rootView.findViewById(R.id.list_enquiry_list);
fab_enquiry = (FloatingActionButton) rootView.findViewById(R.id.fab_enquiry);
enquiry_list_swipe_refresh_layout = (SwipeRefreshLayout) rootView.findViewById(R.id.enquiry_list_swipe_refresh_layout);
enquiry_list_swipe_refresh_layout.setOnRefreshListener(this);
enquiry_list = new ArrayList<HashMap<String, String>>()
enquiry_list_swipe_refresh_layout.post(new Runnable() {
#Override
public void run() {
try {
enquiry_list_swipe_refresh_layout.setRefreshing(true);
queue = Volley.newRequestQueue(getActivity().getApplicationContext());
Activity_Get_Enquiry_List(int_starting_item_no, int_load_more_count);
} catch (Exception e) {
}
}
});
enquiry_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("Event Trigered by Item" );
String str_enquiry_id = enquiry_list.get(position).get(TAG_ID);
String str_customer_id = enquiry_list.get(position).get(TAG_CUSTOMER_ID);
String str_image_enquiry = enquiry_list.get(position).get(TAG_IMAGE_ENQUIRY);
String str_description_enquiry = enquiry_list.get(position).get(TAG_DESCRIPTION);
String str_date_enquiry = enquiry_list.get(position).get(TAG_DATE_ENQUIRY);
String str_project_status = enquiry_list.get(position).get(TAG_PROJECT_STATUS);
String str_created_userid = enquiry_list.get(position).get(TAG_CREATED_USERID);
String str_created_userrole = enquiry_list.get(position).get(TAG_CREATED_USERROLE);
String str_created_datetime = enquiry_list.get(position).get(TAG_CREATED_DATETIME);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("enquiry_id", str_enquiry_id);
editor.putString("customer_id", str_customer_id);
editor.putString("image_enquiry", str_image_enquiry);
editor.putString("description_enquiry", str_description_enquiry);
editor.putString("date_enquiry", str_date_enquiry);
editor.putString("project_status", str_project_status);
editor.putString("created_userid", str_created_userid);
editor.putString("created_role", str_created_userrole);
editor.putString("created_datetime", str_created_datetime);
editor.commit();
Intent i = new Intent(getContext(),Activity_Enquiry_Description.class);
startActivity(i);
}
});
enquiry_listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
// TODO Auto-generated method stub
str_select_task_id = enquiry_list.get(pos).get(TAG_ID);
Delete_Task_alert();
return true;
}
});
return rootView;
}
private void Activity_Get_Enquiry_List(final int int_starting_item_no, final int int_load_more_count) {
StringRequest request = new StringRequest(Request.Method.POST, App_Config.url_list_enquiry, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d(TAG_CUSTOMER_DETAILS, response.toString());
Log.d("TAG_ENQUIRY_LIST", response.toString());
try {
JSONObject obj = new JSONObject(response);
System.out.println("REG 00" + obj);
int success = obj.getInt("success");
System.out.println("REG" + success);
if (success == 1) {
JSONArray enquiry = obj.getJSONArray("Enquiry");
for (int i = 0; enquiry.length() > i; i++) {
JSONObject obj_one = enquiry.getJSONObject(i);
String str_enquiry_id = obj_one.getString(TAG_ID);
String str_customer_id = obj_one.getString(TAG_CUSTOMER_ID);
String str_image_enquiry = obj_one.getString(TAG_IMAGE_ENQUIRY);
String str_description_enquiry = obj_one.getString(TAG_DESCRIPTION);
String str_date_enquiry = obj_one.getString(TAG_DATE_ENQUIRY);
String str_project_status = obj_one.getString(TAG_PROJECT_STATUS);
String str_created_userid = obj_one.getString(TAG_CREATED_USERID);
String str_created_userrole = obj_one.getString(TAG_CREATED_USERROLE);
String str_created_datetime = obj_one.getString(TAG_CREATED_DATETIME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, str_enquiry_id);
map.put(TAG_CUSTOMER_ID, str_customer_id);
map.put(TAG_IMAGE_ENQUIRY, str_image_enquiry);
map.put(TAG_DESCRIPTION, str_description_enquiry);
map.put(TAG_DATE_ENQUIRY, str_date_enquiry);
map.put(TAG_PROJECT_STATUS, str_project_status);
map.put(TAG_CREATED_USERID, str_created_userid);
map.put(TAG_CREATED_USERROLE, str_created_userrole);
map.put(TAG_CREATED_DATETIME, str_created_datetime);
enquiry_list.add(map);
System.out.println("HASHMAP ARRAY" + enquiry_list);
}
Adapter = new Adapter_Enquiry_List(getActivity(), enquiry_list);
enquiry_listView.setAdapter(Adapter);
enquiry_list_swipe_refresh_layout.setRefreshing(false);
} else {
TastyToast.makeText(getContext(), "OOPS FAILED TO LOAD", TastyToast.LENGTH_LONG, TastyToast.WARNING);
}
LoadMoreButtonVisible();
enquiry_list_swipe_refresh_layout.setRefreshing(false);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
enquiry_list_swipe_refresh_layout.setRefreshing(false);
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("user_id", str_user_id);
params.put("start",""+ int_starting_item_no);
params.put("limit",""+ int_load_more_count);
System.out.println("user_id " + str_user_id);
System.out.println("start " + int_starting_item_no);
System.out.println("limit " + int_load_more_count);
return params;
}
};
queue.add(request);
}
}
If there are clickable UI elements like Button, Imagebutton are present in child view of list/Recyclerview, they can take control of click events. So, Recyclerview would not get chance to click event.
Please set android:focusable="false" for all child clickable view. Then your itemclick will work.
You can also use following property in parent view that prevent child view getting focus.
android:descendantFocusability="blocksDescendants"
You implement wrong method of list item click listener, just replace this
enquiry_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
To:
enquiry_listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {}}
I have an app with three fragments which I need to Asynctask every swipe. But it seems that the Asynctask runs only on the opening of the app. But when it's already created, only the first and third fragment functions well when it comes to AsyncTask the second doesn't change when I update the database.
This is my MainActivity.java
package com.example.RadarOperationMonitoringSystem;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
/**
* Created by Lemueloodle on 2/12/14.
*/
public class MainActivity extends FragmentActivity{
ViewPager Tab;
TabPagerAdapter TabAdapter;
ActionBar actionBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
Tab = (ViewPager)findViewById(R.id.viewPager);
Tab.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar = getActionBar();
actionBar.setSelectedNavigationItem(position); }
});
Tab.setAdapter(TabAdapter);
actionBar = getActionBar();
//Enable Tabs on Action Bar
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener(){
#Override
public void onTabReselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
Tab.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(android.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}};
//Add New Tab
actionBar.addTab(actionBar.newTab().setText("FirstFragment").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("SecondFragment").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("ThirdFragment").setTabListener(tabListener));
}
}
This is my TabPagerAdapter
package com.example.RadarOperationMonitoringSystem;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
/**
* Created by Lemueloodle on 2/12/14.
*/
public class TabPagerAdapter extends FragmentStatePagerAdapter {
public TabPagerAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
#Override
public Fragment getItem(int i) {
switch(i) {
case 0:
return new FirstFragment();
case 1:
return new SecondFragment();
case 2:
return new ThirdFragment();
}
return null;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return 3; //No of Tabs
}
}
This is my FirstFragment.java
package com.example.RadarOperationMonitoringSystem;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class FirstFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View first = inflater.inflate(R.layout.first_frag, container, false);
// get the listview
((TextView)first.findViewById(R.id.textView)).setText("SecondFragment");
return first;
}
}
SecondFragment.java
package com.example.RadarOperationMonitoringSystem;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class SecondFragment extends ListFragment {
private ProgressDialog pDialog;
// URL to get contacts JSON
private static final String url = "http://10.0.2.2/radaroperations/networkstatus.php";
private static final String TAG_SITENAME1 = "siteName1";
private static final String TAG_NETSTAT1 = "netlink_stats1";
private static final String TAG_FORECAST1 = "forcasting_stats1";
private static final String TAG_MDSI1 = "pagasa_mdsi_stats1";
private static final String TAG_PNOAH1 = "projectnoah_stats1";
....so on
String site1 = "";
String netstat1 = "";
String forecast1 = "";
String mdsi1 = "";
String pnoah1 = "";
.....so on
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View second = inflater.inflate(R.layout.second_frag, container, false);
((TextView)second.findViewById(R.id.textView)).setText("SecondFragment");
return second;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// We set clear listener
new GetContactsb().execute();
}
public class GetContactsb extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Please wait...");
pDialog.setCancelable(true);
pDialog.show();
}
#Override
public Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler2 sh = new ServiceHandler2();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler2.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject c = new JSONObject(jsonStr);
// Getting JSON Array node
site1 = c.getString(TAG_SITENAME1);
netstat1 = c.getString(TAG_NETSTAT1);
forecast1 = c.getString(TAG_FORECAST1);
mdsi1 = c.getString(TAG_MDSI1);
pnoah1 = c.getString(TAG_PNOAH1);
..so on
// tmp hashmap for single contact
HashMap<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => value
contact.put(TAG_SITENAME1, site1);
contact.put(TAG_NETSTAT1, netstat1);
contact.put(TAG_FORECAST1, forecast1);
contact.put(TAG_MDSI1, mdsi1);
contact.put(TAG_PNOAH1, pnoah1);
...so on
// adding contact to contact list
contactList.clear();
contactList.add(contact);
} catch (JSONException e) {
e.printStackTrace();
}
}else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
#Override
public void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
*
*/
ListAdapter adapter = new SimpleAdapter(
getActivity(), contactList,
R.layout.list_item2, new String[] { TAG_SITENAME1,TAG_SITENAME2,TAG_SITENAME3,TAG_SITENAME4,
TAG_SITENAME5,TAG_SITENAME6,TAG_SITENAME7},
new int[] { R.id.sitename1, R.id.sitename2, R.id.sitename3, R.id.sitename4,R.id.sitename5,
R.id.sitename6, R.id.sitename7}){
//This will change the color of the value depending on the limit given
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView netstata = (TextView) view.findViewById(R.id.netstat1);
TextView forecasta = (TextView) view.findViewById(R.id.forecast1);
TextView mdsia = (TextView) view.findViewById(R.id.pmdsi1);
TextView pnoaha = (TextView) view.findViewById(R.id.pnoah1);
....so on
//1 - Red = No link
//2 - Yellow = Delay
//3 - Green = Good
//Radar 1
//Network Link Status
if (netstat1.equals("1")){
netstata.setText("No-Link");
netstata.setTextColor(getResources().getColor(R.color.red));
}
else if(netstat1.equals("2")){
netstata.setText("Delay");
netstata.setTextColor(getResources().getColor(R.color.yellow));
}
else if(netstat1.equals("3")){
netstata.setText("Good");
netstata.setTextColor(getResources().getColor(R.color.green));
}
...so on to Radar 7
return view;
};
};
// updating listviews
setListAdapter(adapter);
}
}
}
ThirdFragment.java
package com.example.RadarOperationMonitoringSystem;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class ThirdFragment extends ListFragment {
private ProgressDialog pDialog;
// URL to get contacts JSON
private static final String url = "http://10.0.2.2/radaroperations/energyreadings.php";
private static final String TAG_SITENAME1 = "siteName1";
private static final String TAG_FREQUENCY1 = "Frequency1";
private static final String TAG_ACCURRENT1 = "AC_Voltage1";
private static final String TAG_ACVOLTAGE1 = "AC_Current1";
private static final String TAG_FSTAT1 = "Flimitstat1";
private static final String TAG_VSTAT1 = "Vlimitstat1";
private static final String TAG_CSTAT1 = "Climitstat1";
...so on
// contacts JSONArray
JSONObject c = null;
String site1 = "";
String freq1 = "";
String curr1 = "";
String volts1 = "";
String fstat1 = "";
String vstat1 = "";
String cstat1 = "";
.. so on
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View third = inflater.inflate(R.layout.third_frag, container, false);
((TextView)third.findViewById(R.id.textView)).setText("ThirdFragment");
return third;
}
public void StartProgress() {
new GetContactsc().execute();
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// We set clear listener
new GetContactsc().execute();
}
public class GetContactsc extends AsyncTask<Void, Void, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Please wait...");
pDialog.setCancelable(true);
pDialog.show();
}
#Override
public Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler3 sh = new ServiceHandler3();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler3.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject c = new JSONObject(jsonStr);
// Getting JSON Array node
site1 = c.getString(TAG_SITENAME1);
freq1 = c.getString(TAG_FREQUENCY1);
curr1 = c.getString(TAG_ACCURRENT1);
volts1 = c.getString(TAG_ACVOLTAGE1);
fstat1 = c.getString(TAG_FSTAT1);
vstat1 = c.getString(TAG_VSTAT1);
cstat1 = c.getString(TAG_CSTAT1);
...so on
// tmp hashmap for single contact
HashMap<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => value
contact.put(TAG_SITENAME1, site1);
contact.put(TAG_FREQUENCY1, freq1);
contact.put(TAG_ACCURRENT1, curr1);
contact.put(TAG_ACVOLTAGE1, volts1);
contact.put(TAG_FSTAT1, fstat1);
contact.put(TAG_VSTAT1, vstat1);
contact.put(TAG_CSTAT1, cstat1);
...so on
// adding contact to contact list
contactList.clear();
contactList.add(contact);
} catch (JSONException e) {
e.printStackTrace();
}
}else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
#Override
public void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
/**
*
*/
ListAdapter adapter = new SimpleAdapter(
getActivity(), contactList,
R.layout.list_item, new String[] { TAG_SITENAME1, TAG_FREQUENCY1, TAG_ACCURRENT1,
TAG_ACVOLTAGE1,TAG_SITENAME2, TAG_FREQUENCY2, TAG_ACCURRENT2,
TAG_ACVOLTAGE2,TAG_SITENAME3, TAG_FREQUENCY3, TAG_ACCURRENT3,
TAG_ACVOLTAGE3, TAG_SITENAME4, TAG_FREQUENCY4, TAG_ACCURRENT4,
TAG_ACVOLTAGE4, TAG_SITENAME5, TAG_FREQUENCY5, TAG_ACCURRENT5,
TAG_ACVOLTAGE5, TAG_SITENAME6, TAG_FREQUENCY6, TAG_ACCURRENT6,
TAG_ACVOLTAGE6, TAG_SITENAME7, TAG_FREQUENCY7, TAG_ACCURRENT7,
TAG_ACVOLTAGE7},
new int[] { R.id.sitename1, R.id.frequency1,
R.id.accurrent1, R.id.acvoltage1, R.id.sitename2, R.id.frequency2,
R.id.accurrent2, R.id.acvoltage2, R.id.sitename3, R.id.frequency3,
R.id.accurrent3, R.id.acvoltage3, R.id.sitename4, R.id.frequency4,
R.id.accurrent4, R.id.acvoltage4, R.id.sitename5, R.id.frequency5,
R.id.accurrent5, R.id.acvoltage5, R.id.sitename6, R.id.frequency6,
R.id.accurrent6, R.id.acvoltage6, R.id.sitename7, R.id.frequency7,
R.id.accurrent7, R.id.acvoltage7}){
//This will change the color of the value depending on the limit given
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView freqa = (TextView) view.findViewById(R.id.frequency1);
TextView voltsa = (TextView) view.findViewById(R.id.acvoltage1);
TextView curra = (TextView) view.findViewById(R.id.accurrent1);
... so on
//Radar 1
if (fstat1.equals("1")){
freqa.setTextColor(getResources().getColor(R.color.green));
}
else if(fstat1.equals("2")){
freqa.setTextColor(getResources().getColor(R.color.red));
}
if(vstat1.equals("1")){
voltsa.setTextColor(getResources().getColor(R.color.green));
}
else if(vstat1.equals("2")){
voltsa.setTextColor(getResources().getColor(R.color.red));
}
if(cstat1.equals("1")){
curra.setTextColor(getResources().getColor(R.color.green));
}
else if(cstat1.equals("2")){
curra.setTextColor(getResources().getColor(R.color.red));
}
... so on to Radar 7
return view;
};
};
// updating listviews
setListAdapter(adapter);
}
}
}
I had the same problem like u. I think that problem is because ViewPager saves states of last and next pager, and building them before they come. Try setting tab.setOffscreenPageLimit(0). By doing that u may encounter problem that when ever u swipe pages, pages will be rebuild.