RecyclerView items are clickable but invisible - java

I have been struggling a few days with this problem.
It is really strange.
I have a fragment with the following structure.
ScrollView
ConstraintLayout
TextView1
TwoWayView1
TextView2
TwoWayView2
The TwoWayView (RecyclerView library) is being populated with the items,
I added a onItemClickListener to test if the items is indeed there.
So when I tap on an empty space in the area where the item should be. It gives me the correct position and name of that item. But the item is not visible.
I really hope someone can help me.
Here is my code.
fragment_events
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:context="EventsFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvHeaderSocialEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:text="Social Events"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.033"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
<org.lucasr.twowayview.widget.TwoWayView
android:id="#+id/lvSocialEvents"
style="#style/TwoWayView"
android:layout_width="0dp"
android:layout_height="260dp"
android:layout_marginTop="8dp"
android:clipChildren="true"
android:clipToPadding="false"
android:drawSelectorOnTop="false"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvHeaderSocialEvents"
tools:context=".activities.MenuGuillotineActivity"
tools:layout_conversion_absoluteHeight="80dp"
tools:layout_conversion_absoluteWidth="395dp"
tools:layout_conversion_absoluteX="8dp"
tools:layout_conversion_absoluteY="68dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="846dp"
android:text="temp"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="175dp" />
<TextView
android:id="#+id/tvHeaderSportEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:text="Sport Events"
android:textSize="24sp"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/lvSocialEvents" />
<org.lucasr.twowayview.widget.TwoWayView
android:id="#+id/lvSportEvents"
style="#style/TwoWayView"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginTop="8dp"
android:drawSelectorOnTop="false"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvHeaderSportEvents"
tools:LayoutManager="TwoWayLayoutManager"
tools:context=".activities.MenuGuillotineActivity"
tools:layout_conversion_absoluteHeight="80dp"
tools:layout_conversion_absoluteWidth="395dp"
tools:layout_conversion_absoluteX="8dp"
tools:layout_conversion_absoluteY="68dp" />
<TextView
android:id="#+id/tvHeaderOfficialEvents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:text="Official Events"
android:textSize="24sp"
app:layout_constraintHorizontal_bias="0.025"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/lvSportEvents" />
<org.lucasr.twowayview.widget.TwoWayView
android:id="#+id/lvOfficialEvents"
style="#style/TwoWayView"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginTop="8dp"
android:drawSelectorOnTop="false"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvHeaderOfficialEvents"
tools:LayoutManager="TwoWayLayoutManager"
tools:context=".activities.MenuGuillotineActivity"
tools:layout_conversion_absoluteHeight="80dp"
tools:layout_conversion_absoluteWidth="395dp"
tools:layout_conversion_absoluteX="8dp"
tools:layout_conversion_absoluteY="68dp" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
EventsFragment
public class EventsFragment extends Fragment {
ArrayList<EventClass> eventClassArrayList;
RecyclerView.Adapter eventClassEventsAdapter;
TwoWayView lvSocialEvents;
View masterView;
TwoWayView lvSportEvents;
TwoWayView lvOfficialEvents;
StudentClass studentClass;
String studRank;
Context context;
public EventsFragment() {
// Required empty public constructor
}
private void createHeadings(View view) {
TextView lvHeaderSocialEvents = (TextView) view.findViewById(R.id.tvHeaderSocialEvents);
lvHeaderSocialEvents.setTypeface(EasyFonts.caviarDreamsBold(context));
TextView lvHeaderSportEvents = (TextView) view.findViewById(R.id.tvHeaderSportEvents);
lvHeaderSportEvents.setTypeface(EasyFonts.caviarDreamsBold(context));
TextView lvHeaderOfficialEvents = (TextView) view.findViewById(R.id.tvHeaderOfficialEvents);
lvHeaderOfficialEvents.setTypeface(EasyFonts.caviarDreamsBold(context));
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_events, container, false);
masterView = view;
// Get Application Context
context = getContext().getApplicationContext();
Fresco.initialize(context);
// Assign components
lvSocialEvents = (TwoWayView) view.findViewById(R.id.lvSocialEvents);
lvSocialEvents.setLayoutManager(new ListLayoutManager(context, TwoWayLayoutManager.Orientation.HORIZONTAL));
lvSocialEvents.setHasFixedSize(true);
lvSportEvents = (TwoWayView) view.findViewById(R.id.lvSportEvents);
lvSportEvents.setLayoutManager(new ListLayoutManager(context, TwoWayLayoutManager.Orientation.HORIZONTAL));
lvSportEvents.setHasFixedSize(true);
lvOfficialEvents = (TwoWayView) view.findViewById(R.id.lvOfficialEvents);
lvOfficialEvents.setLayoutManager(new ListLayoutManager(context, TwoWayLayoutManager.Orientation.HORIZONTAL));
lvOfficialEvents.setHasFixedSize(true);
createHeadings(view);
// Get global data
SharedPreferences global = context.getSharedPreferences("globalData", MODE_PRIVATE);
if (global.contains("student")) {
//Get json from SP and decode json to EmployeeClass.
SharedPreferences shared = context.getSharedPreferences("studentData", MODE_PRIVATE);
Gson gson = new Gson();
String json = shared.getString("studentObject", "");
studentClass = gson.fromJson(json, StudentClass.class);
studRank = studentClass.rank;
} else {
studRank = "0";
}
// Get all the events from the Web server
StringRequest stringRequest = new StringRequest(Request.Method.POST, getResources().getString(R.string.url_event), new Response.Listener<String>() {
#Override
public void onResponse(String output) {
if (!output.isEmpty()) {
ArrayList<CommunicationClass> data = new JsonConverter<CommunicationClass>().toArrayList(output, CommunicationClass.class);
CommunicationClass comm = data.get(0);
if (comm.code.equals("0")) {
// Create list for Events
eventClassArrayList = new JsonConverter<EventClass>().toArrayList(comm.info, EventClass.class);
// Create and add events to EventsAdapter and add to TwoWayView
eventClassEventsAdapter = new EventsAdapter(context,eventClassArrayList);
lvSocialEvents.setAdapter(eventClassEventsAdapter);
lvSportEvents.setAdapter(eventClassEventsAdapter);
lvOfficialEvents.setAdapter(eventClassEventsAdapter);
eventClassEventsAdapter.notifyDataSetChanged();
} else {
ErrorHandling.makeText(context,comm.code, false).show();
}
} else {
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
ErrorHandling.makeText(context, volleyError).showVolley();
}
}) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
//POST data for PHP Script
HashMap<String, String> postDataEvents = new HashMap<String, String>();
postDataEvents.put("event", "true");
if (studRank.equals("0")) {
postDataEvents.put("token", "public");
} else {
postDataEvents.put("token", studentClass.token);
}
return postDataEvents;
}
};
MySingleton.getInstance(context).addToRequestQueue(stringRequest);
com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport itemClickSupport = com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport.addTo(lvSocialEvents);
itemClickSupport.setOnItemClickListener(new com.example.howldevelopment.bcofficial.interfaces.ItemClickSupport.OnItemClickListener() {
#Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
Toast.makeText(context, eventClassArrayList.get(position).name, Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
EventsAdapter
public class EventsAdapter extends RecyclerView.Adapter<EventsAdapter.EventViewHolder> {
private Context context;
private ArrayList<EventClass> events;
private LayoutInflater mInflater;
public EventsAdapter(Context context,ArrayList<EventClass> events) {
mInflater = LayoutInflater.from(context);
this.context = context;
this.events = events;
}
#Override
public EventViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.event_item_1, parent, false);
EventViewHolder holder = new EventViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(EventViewHolder holder, int position) {
Toast.makeText(context, events.get(position).name, Toast.LENGTH_SHORT).show();
holder.tvName.setText(events.get(position).name);
holder.tvDate.setText(events.get(position).date);
holder.tvCost.setText(events.get(position).cost);
holder.tvInterested.setText(events.get(position).interested);
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public int getItemCount() {
return events.size();
}
class EventViewHolder extends RecyclerView.ViewHolder {
TextView tvName;
TextView tvDate;
TextView tvCost;
TextView tvInterested;
ImageView imgPoster;
public EventViewHolder(View itemView) {
super(itemView);
tvName = (TextView) itemView.findViewById(R.id.tvEventName);
tvDate = (TextView) itemView.findViewById(R.id.tvEventDate);
tvCost = (TextView) itemView.findViewById(R.id.tvEventPrice);
tvInterested = (TextView) itemView.findViewById(R.id.tvEventInterested);
}
}
}
It did work a few hours ago. But after added more components and the required code in the EventsAdapter. It stopped working. And try to go back to the working build, But no success
I also get E/RecyclerView: No adapter attached; skipping layout error

Android Studio showed that my font color was the greyish color, while in real life it was actually white (or my Accent Color).
I just changed the color of the text font and everything was working perfectly.

Related

how may i resolve ListView Problem ? ERROR: on a null object reference

hello guys i'm back again on a question conserning my final project.
i have made a googlemap app with navigation drawer using activity( no fragment). i think you know about that. then rather than using header and menu, i have use a layout where the header should be so that i can make there a listview to display events all of this is clear.
screenshot
MapActivity :
public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final String TAG = "MapActivity";
DrawerLayout drawerLayout;
LinearLayout drawer_up;
FloatingActionsMenu mainfloating;
FloatingActionButton profile, evennement, historique,reglage,aidesupport;
ImageButton zoomin,zoomout,showtail,zoom_auto,showgeofence,maplayer,drawermenugroit,drawermenugauche;
ProgressDialog progressDialog;
private Dialog mDialog;
private GoogleMap map;
private Timer timer;
private int autoZoomedTimes = 0;// dėl bugo osmdroid library, zoom'inam du kartus ir paskui po refresh'o nebe, nes greičiausiai user'is bus pakeitęs zoom'ą
RelativeLayout nodata_layout;
private HashMap<Integer, Marker> deviceIdMarkers;
private HashMap<String, Device> markerIdDevices;
private HashMap<Integer, Polyline> deviceIdPolyline;
private HashMap<Integer, LatLng> deviceIdLastLatLng;
// private HashMap<Integer, Marker> deviceIdSmallMarkerInfo;
private long lastRefreshTime;
boolean isAutoZoomEnabled = true;
boolean isShowTitlesEnabled;
boolean isShowTailsEnabled = true;
boolean isShowGeofencesEnabled = true;
private String stopTime;
ImageButton map_layer_icon;
private AsyncTask downloadingAsync;
#Bind(R.id.listevent)
ListView listevent;
#Bind(R.id.clearAllEvents)
Button clearAllEvents;
#Bind(R.id.list) ListView list;
#Bind(R.id.nodata_layout) RelativeLayout nodata_layout1;
private boolean isRefreshLoced = false;
ApiInterface.GetGeofencesResult geofencesResult;
ArrayList<PolygonWithName> polygonsWithDetails = new ArrayList<>();
float previousZoomLevel = 0;
Boolean isAllFabsVisible;
RelativeLayout content_layout;
//fin de declaration a garder en tete
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
setContentView(R.layout.activity_map);
//devices elements
deviceIdMarkers = new HashMap<>();
markerIdDevices = new HashMap<>();
deviceIdPolyline = new HashMap<>();
deviceIdLastLatLng = new HashMap<>();
final String api_key = (String) DataSaver.getInstance(MapActivity.this).load("api_key");
final EventsAdapter adapter = new EventsAdapter(this);
listevent.setAdapter(adapter);
//deviceIdSmallMarkerInfo = new HashMap<>();
//delaration des boutons pour le compte de floatingButton, etc...;
drawermenugroit = findViewById(R.id.drawermenudroit);
drawer_up = findViewById(R.id.drawerup);
drawermenugauche = findViewById(R.id.drawermenugauche);
drawerLayout = findViewById(R.id.drawer);
// profile = findViewById(R.id.profile);
mainfloating = findViewById(R.id.mainFloatingBtn);
evennement = findViewById(R.id.evennements);
historique = findViewById(R.id.historiques);
reglage = findViewById(R.id.reglages);
aidesupport = findViewById(R.id.aide_support);
zoomin = findViewById(R.id.zoom_in);
LinearLayout list_event = findViewById(R.id.list_event);
zoomout = findViewById(R.id.zoom_out);
showtail = findViewById(R.id.showtails);
zoom_auto = findViewById(R.id.autozoom);
listevent = (ListView) findViewById(R.id.listevent);
list = (ListView) findViewById(R.id.list);
showgeofence = findViewById(R.id.geofences);
maplayer = findViewById(R.id.map_layer);
map_layer_icon = (ImageButton) findViewById(R.id.map_layer);
//loading_bar = (ProgressBar) findViewById(R.id.loading_progBar);
content_layout = (RelativeLayout) findViewById(R.id.content_layout);
nodata_layout = (RelativeLayout) findViewById(R.id.nodata_layout);
//fin de declaration de boutons
//chargement des données
progressDialog = new ProgressDialog(this);
progressDialog = new ProgressDialog(MapActivity.this);
progressDialog.setMessage("En cours..."); // Setting Message
progressDialog.setTitle("Chargement de la carte"); // Setting Title
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // Progress Dialog Style Spinner
progressDialog.show(); // Display Progress Dialog
progressDialog.setCancelable(false);
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
progressDialog.dismiss();
}
}).start();
// fni de chargement des données
//open drawer and load list data in drawer layout button
drawermenugauche.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openDrawer(drawerLayout);
API.getApiInterface(MapActivity.this).getEvents(api_key, getResources().getString(R.string.lang), 0, new Callback<ApiInterface.GetEventsResult>() {
#Override
public void success(ApiInterface.GetEventsResult result, Response response) {
adapter.setArray(result.items.data);
if(result.items.data.size() != 0)
listevent.setVisibility(View.VISIBLE);
else
nodata_layout1.setVisibility(View.VISIBLE);
listevent.setVisibility(View.GONE);
}
#Override
public void failure(RetrofitError retrofitError) {
Toast.makeText(MapActivity.this, R.string.errorHappened, Toast.LENGTH_SHORT).show();
}
});
}
});
drawer_up.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
closeDrawer(drawerLayout);
}
});
zoomin.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
map.animateCamera(CameraUpdateFactory.zoomIn());
}
});
zoomout.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
map.animateCamera(CameraUpdateFactory.zoomOut());
}
});
zoom_auto.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
isAutoZoomEnabled = !isAutoZoomEnabled;
if (isAutoZoomEnabled)
{
zoom_auto.setImageResource(R.drawable.icon2022);
Toast.makeText(MapActivity.this, "Zoom Auto Activé", Toast.LENGTH_SHORT).show();
} else
{
zoom_auto.setImageResource(R.drawable.disableicon2022);
Toast.makeText(MapActivity.this, "Zoom Auto Désactivé", Toast.LENGTH_SHORT).show();
}
}
});
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
// ouverture et fermeture de drawer
private static void openDrawer(DrawerLayout drawerLayout){
drawerLayout.openDrawer(GravityCompat.START);
}
private static void closeDrawer(DrawerLayout drawerLayout){
if(drawerLayout.isDrawerOpen(GravityCompat.START)){
drawerLayout.closeDrawer(GravityCompat.START);
}
}
//fin ouverture et fermeture drawer
......etc...
see my EventsAdapter code below:
public class EventsAdapter extends AwesomeAdapter<Event> {
public EventsAdapter(Context context) {
super(context);
}
ArrayList<Event> original;
#Override
public void setArray(ArrayList<Event> array) {
super.setArray(array);
if(original == null)
original = array;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null)
convertView = getLayoutInflater().inflate(R.layout.adapter_events, null);
Event item = getItem(position);
TextView device_name = (TextView) convertView.findViewById(R.id.device_name);
device_name.setText(item.device_name);
TextView date = (TextView) convertView.findViewById(R.id.date);
date.setText(item.time);
TextView message = (TextView) convertView.findViewById(R.id.message);
message.setText(item.message);
TextView geofence_name = (TextView) convertView.findViewById(R.id.geofence_name);
geofence_name.setText(item.geofence_name);
return convertView;
}
ItemFilter mFilter = new ItemFilter();
public Filter getFilter() {
return mFilter;
}
private class ItemFilter extends Filter {
#Override
protected FilterResults performFiltering(CharSequence constraint)
{
String filterString = constraint.toString().toLowerCase();
FilterResults results = new FilterResults();
final ArrayList<Event> nlist = new ArrayList<>();
for(Event item : original)
{
if(item.fitForFilter(filterString))
nlist.add(item);
}
results.values = nlist;
results.count = nlist.size();
return results;
}
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence constraint, FilterResults results) {
setArray((ArrayList<Event>) results.values);
notifyDataSetChanged();
}
}
}
then in my adapter_event layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#color/whitesplash"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/instance"
android:layout_width="16dp"
android:layout_height="22dp"
android:src="#drawable/custom_floating_button" />
<TextView
android:id="#+id/device_nam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/instance"
android:fontFamily="#font/fjallaoneregular"
android:text="Info Balise"
android:textColor="#color/black"
android:textSize="8dp"
android:textStyle="normal" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/device_nam"
android:outlineAmbientShadowColor="#color/blue" />
<TextView
android:id="#+id/device_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/device_nam"
android:layout_marginStart="16dp"
android:fontFamily="#font/fjallaoneregular"
android:text="device name"
android:textColor="#color/blue"
android:textSize="8dp"
android:textStyle="italic" />
<TextView
android:id="#+id/textspeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_toEndOf="#+id/device_nam"
android:fontFamily="#font/fjallaoneregular"
android:text="Vitesse"
android:textColor="#color/black"
android:textSize="8dp"
android:textStyle="italic" />
<TextView
android:id="#+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textspeed"
android:layout_marginStart="3dp"
android:layout_toEndOf="#+id/device_name"
android:fontFamily="#font/fjallaoneregular"
android:text="speed"
android:textColor="#color/blue"
android:textSize="8dp"
android:textStyle="italic" />
<TextView
android:id="#+id/message1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_toRightOf="#+id/textspeed"
android:fontFamily="#font/fjallaoneregular"
android:text="message"
android:textColor="#color/black"
android:textSize="8dp"
android:textStyle="normal" />
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textspeed"
android:layout_marginStart="3dp"
android:layout_toEndOf="#+id/speed"
android:fontFamily="#font/fjallaoneregular"
android:text="massage"
android:textColor="#color/blue"
android:textSize="8sp"
android:textStyle="italic" />
<View
android:id="#+id/view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/device_name" />
<TextView
android:id="#+id/datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/device_name"
android:layout_toEndOf="#+id/instance"
android:fontFamily="#font/fjallaoneregular"
android:text="date:"
android:textColor="#color/black"
android:textSize="8dp"
android:textStyle="normal" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/device_name"
android:layout_marginStart="3dp"
android:layout_toEndOf="#+id/datetext"
android:fontFamily="#font/fjallaoneregular"
android:text="date"
android:textColor="#color/blue"
android:textSize="8sp"
android:textStyle="italic" />
<TextView
android:id="#+id/geofence_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="geofence_name"
android:fontFamily="#font/lobsterregular"
android:layout_below="#+id/date"
android:layout_marginStart="3dp"
android:layout_toRightOf="#+id/instance"
android:textSize="8dp"
android:textColor="#color/blue"/>
</RelativeLayout>
in this adpater_events i have found no mistake. and in the drawer_tracesas i said before( i am not using menu and header in navigationDrawer i would like to use a layout that i called drawer_traces) like below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/drawerup"
android:orientation="horizontal"
android:background="#color/blue">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/objects"
android:src="#drawable/ic_menu_24"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:text="#string/objects" />
</LinearLayout>
<TextView
android:id="#+id/Liste_Balises"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerup"
android:fontFamily="#font/fjallaoneregular"
android:gravity="center"
android:text="#string/liste_balises"
android:textColor="#color/blue" />
<LinearLayout
android:id="#+id/list_balises"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical"
android:layout_below="#+id/Liste_Balises"
android:layout_marginTop="10dp"
android:minHeight="?android:attr/listPreferredItemHeight">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" />
</LinearLayout>
<TextView
android:id="#+id/list_events"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/list_balises"
android:layout_marginTop="10dp"
android:fontFamily="#font/fjallaoneregular"
android:gravity="center"
android:text="#string/liste_evennemT"
android:textColor="#color/blue" />
<LinearLayout
android:id="#+id/list_event"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#+id/list_events"
android:layout_marginTop="10dp"
android:minHeight="?android:attr/listPreferredItemHeight">
<ListView
android:id="#+id/listevent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" />
</LinearLayout>
<RelativeLayout
android:id="#+id/nodata_layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/list_event"
android:layout_above="#+id/clearAllEvents"
android:background="#ffffff"
android:visibility="gone"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/noEventsData"/>
</RelativeLayout>
<Button
android:id="#+id/clearAllEvents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/list_event"
android:fontFamily="#font/fjallaoneregular"
android:text="Effacer Evennements"/>
</RelativeLayout>
this layout (drawer_trace) will be displayed in mapActivity as a navigation Drawer. we are ok for that.
and then i have my Events Model:
public class Event
{
public int id, user_id, device_id, position_id, alert_id;
// geofence_id
public String message;
public String address;
public float altitude;
// course
public float latitude, longitude;
// power
public float speed;
public String time;
// deleted
public String device_name, geofence_name;
public boolean fitForFilter(String filterString) {
if(message.toLowerCase().contains(filterString.toLowerCase()))
return true;
if(address.toLowerCase().contains(filterString.toLowerCase()))
return true;
if(time.toLowerCase().contains(filterString.toLowerCase()))
return true;
if(device_name.toLowerCase().contains(filterString.toLowerCase()))
return true;
if(geofence_name.toLowerCase().contains(filterString.toLowerCase()))
return true;
return false;
}
i am using REST API in backend and retrofit.
everything is ok untill i try to eun the app.
it says ERROR MESSAGE:
Process: com.gabontech.gprstest, PID: 14460
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gabontech.gprstest/com.gabontech.gprstest.activities.MapActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3433)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3572)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2097)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:7663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at com.gabontech.gprstest.activities.MapActivity.onCreate(MapActivity.java:139)
at android.app.Activity.performCreate(Activity.java:7805)
at android.app.Activity.performCreate(Activity.java:7794)
i think about the adapter where in EventsAdapter.class line ref:::::
convertView = getLayoutInflater().inflate(R.layout.adapter_events, null);
ihave spent two days there. please if you can help it will give me a hand for my exam. Thank so much guys

how can disable scroll recyclerView when moving map?

I created a recyclerView that has several items but the problem is when I want to look for the address inside the map
When I scroll through the map, the recycler view shifts and the map loses scrollability.
enter link description here
//Recycler View Adapter Class
public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.Holder> {
private List<FakeAddressList> objectList;
public AddressAdapter(List<FakeAddressList> list) {
this.objectList = list;
}
#NonNull
#Override
public Holder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_address, parent, false);
return new Holder(view);
}
#Override
public void onBindViewHolder(#NonNull Holder holder, int position) {
holder.bindAddressList(objectList.get(position));
holder.imgClose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
objectList.remove(position);
notifyDataSetChanged();
}
});
holder.imgEditLocation.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AddAddressFragment addressFragment = new AddAddressFragment();
FragmentTransaction ft = fm.beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("Title", objectList.get(position).getTitle());
bundle.putString("Address", objectList.get(position).getAddress());
bundle.putString("Phone", objectList.get(position).getPhoneNumber());
addressFragment.setArguments(bundle);
ft.replace(R.id.content_view, addressFragment).addToBackStack(null).commit();
}
});
holder.FooterLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AddDataFragment addDataFragment = new AddDataFragment();
FragmentTransaction ft = fm.beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("Title", objectList.get(position).getAddress());
bundle.putString("Address", objectList.get(position).getAddress());
bundle.putString("Phone", objectList.get(position).getPhoneNumber());
addDataFragment.setArguments(bundle);
ft.replace(R.id.content_view, addDataFragment).addToBackStack(null).commit();
}
});
}
#Override
public int getItemCount() {
return objectList.size();
}
public class Holder extends RecyclerView.ViewHolder {
public TextView txtTitle;
public TextView txtSelect;
public TextView txtAddress;
public TextView txtPhone;
public ImageView imgClose;
public ImageView imgEditLocation;
public ConstraintLayout FooterLayout;
public MapView map;
public Holder(#NonNull View itemView) {
super(itemView);
txtTitle = itemView.findViewById(R.id.txtTitle);
txtAddress = itemView.findViewById(R.id.txtAddress);
txtPhone = itemView.findViewById(R.id.txtPhoneNumber);
txtSelect = itemView.findViewById(R.id.txtSelect);
imgClose = itemView.findViewById(R.id.imgClose);
imgEditLocation = itemView.findViewById(R.id.imgEditLocation);
FooterLayout = itemView.findViewById(R.id.FooterLayout);
map = itemView.findViewById(R.id.mapView);
txtTitle.setTypeface(Font_shabnam);
txtAddress.setTypeface(Font_shabnam);
txtPhone.setTypeface(Font_shabnam);
txtSelect.setTypeface(Font_shabnam);
}
public void bindAddressList(final FakeAddressList fakeAddressList) {
txtTitle.setText(fakeAddressList.getTitle());
txtAddress.setText(fakeAddressList.getAddress());
txtPhone.setText(fakeAddressList.getPhoneNumber());
if (fakeAddressList.getLng() != null) {
double lng = Double.valueOf(fakeAddressList.getLng());
double lat = Double.valueOf(fakeAddressList.getLat());
addUserMarker(new LngLat(lng, lat));
map.setFocalPointPosition(
new LngLat(Double.valueOf(fakeAddressList.getLng()), Double.valueOf(fakeAddressList.getLat())), 0.25f);
} else {
LngLat focalPoint;
focalPoint = new LngLat(51.33800, 35.69997);
map.setFocalPointPosition(focalPoint, 0f);
}
map.setZoom(15, 0.25f);
map.getLayers().add(NeshanServices.createBaseMap(NeshanMapStyle.STANDARD_DAY));
}
// This method gets a LngLat as input and adds a marker on that position
private void addUserMarker(LngLat loc) {
Marker marker;
VectorElementLayer userMarkerLayer;
userMarkerLayer = NeshanServices.createVectorElementLayer();
map.getLayers().add(userMarkerLayer);
// Creating marker style. We should use an object of type MarkerStyleCreator, set all features on it
// and then call buildStyle method on it. This method returns an object of type MarkerStyle
MarkerStyleCreator markStCr = new MarkerStyleCreator();
markStCr.setSize(20f);
// markStCr.setBitmap(BitmapUtils.createBitmapFromAndroidBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_marker)));
markStCr.setBitmap(BitmapUtils.createBitmapFromAndroidBitmap(BitmapFactory.decodeResource(itemView.getResources(), R.drawable.ic_cherry)));
MarkerStyle markSt = markStCr.buildStyle();
// Creating user marker
marker = new Marker(loc, markSt);
// Clearing userMarkerLayer
// userMarkerLayer.clear();
// Adding user marker to userMarkerLayer, or showing marker on map!
userMarkerLayer.add(marker);
}
}
}
Recycler View Xml Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/HeaderLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="#drawable/_orange_shape_b_r_l"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<ImageView
android:id="#+id/imgClose"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_close"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imgEditLocation"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_edit_location"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تهرانپارس"
android:textSize="18dp"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="#+id/imgEditLocation"
app:layout_constraintEnd_toStartOf="#+id/imgEditLocation"
app:layout_constraintStart_toEndOf="#+id/imgClose"
app:layout_constraintTop_toTopOf="#+id/imgClose" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/MiddleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/HeaderLayout"
app:layout_constraintVertical_bias="0.0">
<org.neshan.ui.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imgAddress"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_address"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/mapView"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/txtAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="خیابان فلانی کوچه 1"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="#+id/imgAddress"
app:layout_constraintTop_toTopOf="#+id/imgAddress" />
<ImageView
android:id="#+id/imgPhone"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_phone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/imgAddress"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/txtPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0916123456"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="#+id/imgPhone"
app:layout_constraintTop_toTopOf="#+id/imgPhone" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/FooterLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/_black_shape_t_r_l"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/MiddleLayout"
app:layout_constraintVertical_bias="0.0">
<TextView
android:id="#+id/txtSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="انتخاب"
android:textColor="#color/white"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
//Fragment that Load Recyclerview
public class RegisterAddressFragment extends Fragment
implements View.OnClickListener {
private RecyclerView recycler_SelectAddress;
private Button btnNewAddress;
private ProgressBar progressBar;
private ConstraintLayout MainLayout;
private Bundle bundle;
private ArrayList<FakeAddressList> list = new ArrayList<>();
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.bundle = getArguments();
if (bundle != null) {
list.add(new FakeAddressList(bundle.getString("Title"),
bundle.getString("Address"),
bundle.getString("Phone"),
bundle.getString("Lng"),
bundle.getString("Lat")));
}
}
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_register_address, container, false);
init(v);
initRecyclerView();
return v;
}
private void init(View v) {
recycler_SelectAddress = v.findViewById(R.id.recycler_SelectAddress);
btnNewAddress = v.findViewById(R.id.btnNewAddress);
btnNewAddress.setOnClickListener(this);
progressBar = v.findViewById(R.id.progressbar);
MainLayout = v.findViewById(R.id.MainLayout);
Thread thread = new Thread() {
#Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
// Do some stuff
progressBar.setVisibility(View.GONE);
MainLayout.setVisibility(View.VISIBLE);
}
});
}
};
thread.start(); //start the thread
}
private void initRecyclerView() {
list.add(new FakeAddressList("اصفهان", "شاهین شهر خیابان نوشین پلاک 1", "987654321"));
list.add(new FakeAddressList("اهواز", "کیانپارس کوچه بنی هاشم پلاک 33", "123456789"));
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setOrientation(RecyclerView.VERTICAL);
AddressAdapter addressAdapter = new AddressAdapter(list);
recycler_SelectAddress.setLayoutManager(layoutManager);
recycler_SelectAddress.setAdapter(addressAdapter);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnNewAddress:
AddAddressFragment addressFragment = new AddAddressFragment();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.content_view, addressFragment).addToBackStack(null).commit();
break;
}
}
}
Fragment Xml File
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#color/tusi"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#color/red2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/MainLayout"
tools:visibility="visible"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_SelectAddress"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toTopOf="#+id/btnNewAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/btnNewAddress"
android:layout_width="match_parent"
android:layout_height="0dp"
android:backgroundTint="#color/navy_blue"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
android:text="آدرس جدید"
android:textSize="22sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I found the solution :
I added below code in the adapter of the recyclerview
map.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
itemView.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

RecyclerView create views with x amount of rows

I want to create dynamic views with x number of rows for each CardView that gets created. To help illustrate my idea this image shows what I essentially want to do.
For each CardView I want to be able to put any amount of TableRows into the CardView. So one CardView could have 4 rows whereas the next CardView could have 2 rows and so on.
EDIT: Implementation
Essentially this view is replicated several times, I would like to minimise having to write seperate layouts for each CardView with x amount of rows like in the Card Storage implemenation which is more reusable than what I currently have. As I hit the limit here, I have posted a pastebin of the current layout with rows that I have
https://pastebin.com/9RFDGhXv
Layout: Card Storage
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
style="#style/CardStyle">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/MainConstraints" >
<TableRow
android:id="#+id/row_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="#+id/card_title"
style="#style/Title"/>
</TableRow>
<TableRow
android:id="#+id/row_two"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="#+id/row_one"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<android.support.constraint.ConstraintLayout>
<ImageView
android:id="#+id/drawable"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
style="#style/RowDrawableElement"
/>
<TextView
android:id="#+id/percentage_descriptor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="#id/drawable"
android:text="#string/percentage_descriptor"
style="#style/RowTextElement" />
<TextView
android:id="#+id/percentage_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
style="#style/RowTextElement" />
</android.support.constraint.ConstraintLayout>
</TableRow>
<TableRow
android:id="#+id/row_three"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/row_two"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
style="?android:attr/progressBarStyleHorizontal"
/>
</TableRow>
<TableRow
android:id="#+id/row_four"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/row_three"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<android.support.constraint.ConstraintLayout>
<TextView
android:id="#+id/text_used"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
/>
<TextView
android:id="#+id/text_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
</TableRow>
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Adapter
public class StorageAdapter extends RecyclerView.Adapter<StorageAdapter.MyViewHolder> {
private Context mContext;
private List<StorageObjects> mList;
public StorageAdapter(Context context, List<StorageObjects> list) {
this.mContext = context;
this.mList = list;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_storage, parent, false);
return new MyViewHolder(view);
}
#SuppressLint("SetTextI18n")
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
StorageObjects storageObjects = mList.get(position);
long used = storageObjects.getUsed();
long total = storageObjects.getTotal();
holder.mProgress.setMax(0);
holder.mProgress.setProgress(0);
holder.mTitle.setText(storageObjects.getTitle());
MiscUtils.testDrawableIdentifier(mContext.getApplicationContext(), holder.mImageViews, storageObjects.getDrawables());
holder.mPercentage.setText(storageObjects.getPercentage() + mContext.getString(R.string.percentage));
holder.mProgress.setMax((int) (total/100000));
holder.mProgress.setProgress((int) (used/100000));
holder.mUsed.setText(MiscUtils.humanReadableByteSize(used));
holder.mTotal.setText(MiscUtils.humanReadableByteSize(total));
}
#Override
public int getItemCount() {
return mList.size();
}
static class MyViewHolder extends RecyclerView.ViewHolder {
#BindView(R.id.card_title) TextView mTitle;
#BindViews({R.id.drawable}) List<ImageView> mImageViews;
#BindView(R.id.percentage_text) TextView mPercentage;
#BindView(R.id.progress_bar) ProgressBar mProgress;
#BindView(R.id.text_used) TextView mUsed;
#BindView(R.id.text_total) TextView mTotal;
MyViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
}
Class Storage
public class Storage extends Fragment {
private Unbinder mUnbinder;
private List<StorageObjects> storageList;
private StorageAdapter adapter;
private RecyclerView.LayoutManager mLayoutManager;
#BindArray(R.array.storage_ic_images)
String mDrawables[];
#BindView(R.id.recycler_view)
RecyclerView mRecyclerView;
public Storage() {
// Required empty public constructor
}
public static Storage newInstance() {
return new Storage();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_storage, container, false);
mUnbinder = ButterKnife.bind(this, view);
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onResume() {
super.onResume();
initRecyclerView();
}
#Override
public void onDestroy() {
super.onDestroy();
mUnbinder.unbind();
}
private void initRecyclerView() {
storageList = new ArrayList<>();
adapter = new StorageAdapter(getActivity(), storageList);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(mLayoutManager = ViewUtils.getLayoutManager(getActivity()));
mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(2, ViewUtils.dpToPx(
getActivity(), 10), true));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setAdapter(adapter);
prepareView();
}
#SuppressLint("SetTextI18n")
private void prepareView(){
StorageObjects storage
= new StorageObjects(
getActivity().getString(R.string.int_storage_title),
StorageUtils.internalUsed(),
StorageUtils.internalTotal(),
StorageUtils.internalPercentage(),
mDrawables[0]);
storageList.add(storage);
storage = new StorageObjects (
getActivity().getString(R.string.ext_storage_title),
StorageUtils.externalUsed(getActivity()),
StorageUtils.externalTotal(getActivity()),
StorageUtils.externalPercentage(getActivity()),
mDrawables[1]
);
storageList.add(storage);
adapter.notifyDataSetChanged();
}
}
If number of rows per card view is less then you can inflate edit text and add it to linear layout.
Note : It's a bad practice to add scroll view inside a scroll view

BaseAdapter gets me only the first position in ListView Android

I've a major isse with an adapter to show every single row item in a ListView and I only get the first value of the index position.
I've an array of comments from a webservice in android. It's an array inside an array.
The main JSONArray it's "noticias" with has a lot of the previews jsonobject. Now: "comments" it's another array.
This is my ContenidoNews.java class. I pass the "comment" array in a intent from the previews Activity:
public class ContenidoNews extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{
private ActionBar bar;
String tituloDetail;
String fullDetail;
String imagenDetail;
String permalink;
String author;
String authorimg;
String dayofmonth;
String month;
String views;
String totalcomments;
String arraycomments;
private SquareImageView mainPic;
private CircularImageView authorpic;
private TextView authors;
private TextView contentTxt;
private ScrollView scollMain;
private TextView mainTxt;
private Animation animSlideDown;
private RelativeLayout relativeAnim;
private RelativeLayout namereceipt;
private Typeface texto;
private Button btnshare;
// Universal Image Loader
private DisplayImageOptions options;
private ImageLoader il = ImageLoader.getInstance();
private DisplayImageOptions opts;
private File cacheDir;
private String imgauthor;
private TextView tvday;
private TextView tvmonth;
private Typeface textofat;
private LinearLayout datestv;
private WebView webview;
private ArrayList links;
private String urlscap;
private String newstring;
private String copyfull;
private String youtube;
private YouTubePlayerView youTubePlayerView;
private String youtubeb;
private String youtubec;
private String youtubed;
private TextView tvtotal;
private TextView tvvisitas;
private String youtubee;
private String youtubef;
private JSONArray arrayComment;
ArrayList<HashMap<String, String>> arrayofcomments;
private ListView listcomment;
private ListAdapter adapter;
private TextView numbcomment;
private TextView tvcomment;
static String AUTHOR = "comauthor";
static String COMMENT = "comtext";
// Grab URLs from text
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contenido);
bar = getActionBar();
bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradiente));
bar.setDisplayHomeAsUpEnabled(true);
bar.setTitle("");
webview = (WebView) findViewById(R.id.wvhit);
webview.getSettings().setJavaScriptEnabled(true);
youTubePlayerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
youTubePlayerView.initialize(API_KEY, this);
Intent i = getIntent();
// Get the result of titulo
tituloDetail = i.getStringExtra("titulo").replace("“", "\"").replace("”", "\"").replace("…", "...").replace("–", "-");
// Get the result of full
fullDetail = i.getStringExtra("full");
// Get the result of imagen
imagenDetail = i.getStringExtra("imagen");
// Get the result of permalink
permalink = i.getStringExtra("permalink");
// Get the result of author
author = i.getStringExtra("author");
// Get the result of authorimg
authorimg = i.getStringExtra("authorimg");
int urlimg = authorimg.lastIndexOf("s=128&");
imgauthor = "http://" + authorimg.substring(9, urlimg + 5);
// Get the result of dayofmonth
dayofmonth = i.getStringExtra("dayofmonth");
// Get the result of month
month = i.getStringExtra("month");
// Get the result of views
views = i.getStringExtra("views");
// Get the result of total comments
totalcomments = i.getStringExtra("totalcomments");
// Get the result of array comments
arraycomments = i.getStringExtra("arraycomments");
webview.setWebViewClient(new WebViewClient());
webview.loadUrl(permalink);
pullLinks(fullDetail);
copyfull = fullDetail;
new JSONParser().execute();
texto = Typeface.createFromAsset(this.getAssets(),
"Light.ttf");
textofat = Typeface.createFromAsset(this.getAssets(),
"Bold.ttf");
listcomment = (ListView) findViewById(R.id.listofcomments);
datestv = (LinearLayout) findViewById(R.id.datestv);
tvday = (TextView) findViewById(R.id.tvday);
tvmonth = (TextView) findViewById(R.id.tvmonth);
tvday.setText(dayofmonth);
tvmonth.setText(month);
tvtotal = (TextView) findViewById(R.id.totalvisitas);
tvtotal.setText(views);
tvtotal.setTypeface(textofat);
tvvisitas = (TextView) findViewById(R.id.TVvisitas);
if(views.contentEquals("1")){
tvvisitas.setText("VISITA");
}else{
tvvisitas.setText("VISITAS");
}
tvvisitas.setTypeface(texto);
tvday.setTypeface(textofat);
tvmonth.setTypeface(texto);
mainPic = (SquareImageView) findViewById(R.id.fullimg);
authorpic = (CircularImageView) findViewById(R.id.profile_settings_img);
btnshare = (Button) findViewById(R.id.btnshare);
ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
if (scrollView instanceof Parallaxor) {
((Parallaxor) scrollView).parallaxViewBy(mainPic, 0.6f);
}
relativeAnim = (RelativeLayout) findViewById(R.id.animtext);
animSlideDown = AnimationUtils.loadAnimation(getApplicationContext(),
R.animator.slidetodown);
relativeAnim.startAnimation(animSlideDown);
il.displayImage(imagenDetail, mainPic,opts,new ImageLoadingListener() {
#Override
public void onLoadingStarted(String s, View itemView) {
}
#Override
public void onLoadingFailed(String s, View itemView, FailReason failReason) {
}
#Override
public void onLoadingComplete(String imageUri, View itemView, Bitmap bitmap) {
SquareImageView imageView = (SquareImageView) itemView;
if (bitmap != null) {
FadeInBitmapDisplayer.animate(imageView, 500);
}
}
#Override
public void onLoadingCancelled(String s, View view) {
}
});
il.displayImage(imgauthor, authorpic,opts,new ImageLoadingListener() {
#Override
public void onLoadingStarted(String s, View itemView) {
}
#Override
public void onLoadingFailed(String s, View itemView, FailReason failReason) {
}
#Override
public void onLoadingComplete(String imageUri, View itemView, Bitmap bitmap) {
CircularImageView imageView = (CircularImageView) itemView;
if (bitmap != null) {
FadeInBitmapDisplayer.animate(imageView, 500);
}
}
#Override
public void onLoadingCancelled(String s, View view) {
}
});
contentTxt = (TextView) findViewById(R.id.textnoti);
if(links.size() != 0 && urlscap.contains("youtu")){
youTubePlayerView.setVisibility(View.VISIBLE);
contentTxt.setText(newstring);
}else{
youTubePlayerView.setVisibility(View.GONE);
contentTxt.setText(fullDetail);
}
authors = (TextView) findViewById(R.id.authors);
authors.setText(author);
authors.setTypeface(texto);
mainTxt = (TextView) findViewById(R.id.tituloreceipt);
mainTxt.setText(tituloDetail);
mainTxt.setTypeface(texto);
namereceipt = (RelativeLayout) findViewById(R.id.namereceipt);
Resources res = getResources();
final TypedArray myImages = res.obtainTypedArray(R.array.image);
final Random random = new Random();
//Genrate a random index in the range
int randomInt = random.nextInt(myImages.length());
// Generate the drawableID from the randomInt
int drawableID = myImages.getResourceId(randomInt, -1);
namereceipt.setBackgroundResource(drawableID);
numbcomment = (TextView) findViewById(R.id.numbofcomments);
numbcomment.setText(totalcomments);
tvcomment = (TextView) findViewById(R.id.textforcomments);
if(totalcomments.contentEquals("1")){
tvcomment.setText("COMENTARIO");
}else{
tvcomment.setText("COMENTARIOS");
}
}
My AsyncTask
private class JSONParser extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
try {
arrayofcomments = new ArrayList<HashMap<String, String>>();
arrayComment = new JSONArray(arraycomments);
for(int e = 0; e < arrayComment.length(); e++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject come = arrayComment.getJSONObject(e);
map.put("comauthor", come.getString("comment_author"));
map.put("comtext", come.getString("comment_content"));
arrayofcomments.add(map);
}
} catch (Exception e1) {
}
return null;
}
#Override
protected void onPostExecute(Void args) {
adapter = new ListAdapter(getApplicationContext(), arrayofcomments);
listcomment.setAdapter(adapter);
}
}
The result of arrayComment it's:
[
{
"comment_author_url": "http://www.xxxx.com",
"comment_type": "",
"comment_author_IP": "xxxx",
"comment_author": "Mariano xxxx",
"comment_parent": "0",
"comment_agent": "xxxx",
"comment_karma": "0",
"comment_author_email": "xxxx#xxxx.com",
"comment_date": "2014-10-08 17:31:58",
"comment_post_ID": "593",
"comment_ID": "8",
"comment_content": "Prueba",
"user_id": "2",
"comment_date_gmt": "2014-10-08 20:31:58",
"comment_approved": "1"
},
{
"comment_author_url": "",
"comment_type": "",
"comment_author_IP": "xxxx",
"comment_author": "Susana A xxxx",
"comment_parent": "0",
"comment_agent": "xxxx",
"comment_karma": "0",
"comment_author_email": "xxxxxx#yahoo.com.ar",
"comment_date": "2014-10-08 08:28:00",
"comment_post_ID": "593",
"comment_ID": "7",
"comment_content": "una clarísima definición",
"user_id": "0",
"comment_date_gmt": "2014-10-08 11:28:00",
"comment_approved": "1"
}
]
So far so good... now I need to pass all this to my adapter:
public class ListAdapter extends BaseAdapter {
// Declare Variables
Context context;
LayoutInflater inflater;
private ArrayList<HashMap<String, String>> data;
private HashMap<String, String> resultp;
public ListAdapter(Context context,
ArrayList<HashMap<String, String>> d) {
this.context = context;
data = d;
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int position) {
return data.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView author;
TextView comment;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.comment_item, parent, false);
resultp = new HashMap<String, String>();
final int pos = position;
resultp = data.get(position);
Log.e("data", data.get(position).toString());
author = (TextView) itemView.findViewById(R.id.tvauthorcomment);
author.setText(resultp.get(ContenidoNews.AUTHOR));
author.setTypeface(textofat);
comment = (TextView) itemView.findViewById(R.id.tvofcomment);
comment.setText(resultp.get(ContenidoNews.COMMENT));
comment.setTypeface(texto);
return itemView;
}
}
The result of Log.e("data full", data.toString()); its:
10-08 22:33:40.564: E/data full(26463): [{comtext=Prueba, comauthor=Mariano xxxx}, {comtext=una clarísima definición, comauthor=Susana A xxxx}]
Which, by the way, prints 7 times in the log... but it has the 2 values as I need.
Now... this it's what Log.e("data", data.get(position).toString()); gives me:
10-08 22:21:11.444: E/data(24618): {comtext=Prueba, comauthor=Mariano xxxx}
And:
author.setText(resultp.get(ContenidoNews.AUTHOR));
comment.setText(resultp.get(ContenidoNews.COMMENT));
In the adapter also only gave me the first value in my listview (comment_item.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tvauthorcomment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="20dp"
android:text="Autor Comentario"
android:textColor="#707070"
android:textSize="20sp" />
<TextView
android:id="#+id/tvofcomment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:paddingLeft="30dp"
android:paddingRight="20dp"
android:text="Contenido del comentario"
android:textColor="#707070"
android:textSize="19sp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#BBBBBB" />
</LinearLayout>
</LinearLayout>
I can only get the first value... I can't fix this. I'm stock since a lot of hours and nothing. I don't understand what it's the problem. Please, help!
I would thanks any answer in advance!
EDIT: This is my contenido.xml with the scrollview and the listview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.renderas.suup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" xmlns:app1="http://schemas.android.com/apk/res/com.mkiisoft.masradio">
<WebView
android:id="#+id/wvhit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<com.mkiisoft.masradio.utils.SquareImageView
android:id="#+id/fullimg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:scaleType="centerCrop" />
<LinearLayout
android:id="#+id/datestv"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="190dp"
android:background="#90000000" >
<TextView
android:id="#+id/tvday"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="04"
android:textColor="#FFF"
android:textSize="24sp" />
<TextView
android:id="#+id/tvmonth"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Octubre"
android:textColor="#FFF"
android:textSize="24sp" />
</LinearLayout>
<uk.co.chrisjenx.paralloid.views.ParallaxScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="240dp" >
<FrameLayout
android:id="#+id/imagecontainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/namereceipt"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_gravity="bottom"
android:background="#drawable/bggreenyl" >
<TextView
android:id="#+id/tituloreceipt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|left"
android:paddingBottom="8dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:text="Noticia Titulo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textSize="24sp" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:id="#+id/animtext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/imagecontainer"
android:background="#FFFFFF" >
<com.mkiisoft.masradio.utils.CircularImageView
android:id="#+id/profile_settings_img"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="#drawable/emptypro" />
<TextView
android:id="#+id/authors"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/profile_settings_img"
android:gravity="center_vertical"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#606060"
android:textSize="21sp" />
<LinearLayout
android:id="#+id/linearviews"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_below="#id/authors"
android:layout_marginLeft="15dp"
android:layout_marginTop="8dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgvisitas"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:alpha="0.7"
android:src="#drawable/eyeviewsblack" />
<TextView
android:id="#+id/totalvisitas"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="7"
android:textColor="#606060"
android:textSize="17sp" />
<TextView
android:id="#+id/TVvisitas"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:text="VISITAS"
android:textColor="#606060"
android:textSize="17sp" />
</LinearLayout>
<Button
android:id="#+id/btnshare"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#id/linearviews"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="12dp"
android:background="#drawable/share_btn"
android:text="COMPARTIR"
android:textColor="#color/checktxt" />
<TextView
android:id="#+id/textnoti"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/btnshare"
android:paddingBottom="20dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="10dp"
android:text="Texto de la noticia"
android:textColor="#707070"
android:textSize="18sp" />
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtubeplayerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textnoti"
android:layout_marginBottom="20dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="5dp" />
<LinearLayout
android:id="#+id/linearofcomments"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#id/youtubeplayerview"
android:layout_marginLeft="15dp"
android:gravity="center_vertical|left" >
<TextView
android:id="#+id/numbofcomments"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="0"
android:textColor="#707070"
android:textSize="23sp" />
<TextView
android:id="#+id/textforcomments"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:text="COMENTARIOS"
android:textColor="#707070"
android:textSize="23sp" />
</LinearLayout>
<ListView
android:id="#+id/listofcomments"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#id/linearofcomments"
android:layout_marginBottom="30dp"
android:layout_marginTop="5dp" >
</ListView>
</RelativeLayout>
</RelativeLayout>
</uk.co.chrisjenx.paralloid.views.ParallaxScrollView>
</RelativeLayout>
We shouldn’t use ListView inside the ScrollView because the list view is already ScrollView, the items in list view are already scrollable..
If you use then the list view will show only one item from the adapter.
Check this post ListView inside scrollview for more details...

Adding Custom Header to List Fragment in Android

I am trying to add a custom header that isnt clickable but will have a checkbox that will "check all" checkboxes under it.
This is my List Fragment
public class AssesmentListFragment extends ListFragment {
private static String BUNDLE_KEY_APPLICATION = "LIST_ITEM";
FastAssesmentListAdapter adapter;
View listHeader;
public AssesmentListFragment() {}
public AssesmentListFragment(Data[] data) {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Data[] assestments = {new Data("Assesment ID","Name", "Date"), new Data("123456", "Assestment 2", "9/12/12"),
new Data("345672", "Assesment 3", "9/13/12"), new Data("566893", "Assesment 4", "9/14/12")};
//This is the part that makes the app crash
View header = getActivity().getLayoutInflater().inflate(R.layout.list_adapter_assesments, null);
ListView listView = getListView();
listView.addHeaderView(header);
adapter = new FastAssesmentListAdapter(getActivity(), assestments);
setListAdapter(adapter);
updateList(assestments);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
private void updateList(Data[] assestments) {
// NOTE: addAll is not being used to support pre-honeycomb devices
synchronized(adapter) {
adapter.clear();
adapter.addAll(assestments);
adapter.notifyDataSetChanged();
}
}
#Override
public void onListItemClick(ListView parentView, View selectedItemView, int position, long id) {
String model = (String) parentView.getItemAtPosition(position);
((FacilityActivity) getActivity()).onItemSelected(model);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//outState.putInt("curChoice", mCurCheckPosition);
}
}
This is the layout I am trying to use for header
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="25dp"
android:paddingRight="10dp"
android:orientation="horizontal">
<TextView android:id="#+id/adapter_header_textview_column1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textColor="#color/defaultTextColor"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="28sp"
android:text="Assesment ID" />
<TextView android:id="#+id/adapter_header_textview_column2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textColor="#color/defaultTextColor"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="28sp"
android:text="Name" />
<TextView android:id="#+id/adapter_header_textview_column3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textColor="#color/defaultTextColor"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="28sp"
android:text="Date"/>
<CheckBox
android:id="#+id/header_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:color="#color/defaultTextColor"
android:layout_weight=".5"
android:gravity="center" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#color/BPGreenColor" />
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Then this is the array adapter I am using:
public class FastAssesmentListAdapter extends ArrayAdapter<Data> {
private static int LAYOUT_ID = R.layout.list_adapter_with_checkbox_three_column;
private final Data[] assesments;
private final Context context;
LinearLayout listHeader;
static class ViewHolder {
protected TextView column1;
protected TextView column2;
protected TextView column3;
protected CheckBox checkbox;
}
public FastAssesmentListAdapter(Context context, Data[] assesments) {
super(context, LAYOUT_ID, assesments);
this.context = context;
this.assesments = assesments;
}
//ListFragment and array adapter will automatically call this over and over to auto populate the list
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final Data item = getItem(position);
// Formulate row view (create if it does not exist yet)
View view = convertView;
if(view == null) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
view = inflater.inflate(LAYOUT_ID, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.column1 = (TextView) view.findViewById(R.id.adapter_textview_column1);
viewHolder.column2 = (TextView) view.findViewById(R.id.adapter_textview_column2);
viewHolder.column3 = (TextView) view.findViewById(R.id.adapter_textview_column3);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check_box);
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "Clicked",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getContext(), FacilityActivity.class);
getContext().startActivity(intent);
}
});
if(viewHolder.checkbox != null) {
viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked) {
item.setSelected(isChecked);
Toast.makeText(getContext(), "Checked",
Toast.LENGTH_SHORT).show();
}
}
});
}
view.setTag(viewHolder);
viewHolder.checkbox.setTag(position);
}
ViewHolder viewHolder = (ViewHolder) view.getTag();
viewHolder.checkbox.setTag(position);
viewHolder.column1.setText(item.getColumn1());
viewHolder.column2.setText(item.getColumn2());
viewHolder.column3.setText(item.getColumn3());
viewHolder.checkbox.setChecked(item.isSelected());
return view;
}
}
on a side note, the onlistitemclicked in the fragment doesnt work, i have to set a listener in the adapter and then it works. any ideas on that? but mainly I need to figure out how to use a custom header and custom rows in the list view. Here is the layout for the rows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="25dp"
android:paddingRight="10dp"
android:orientation="horizontal">
<TextView android:id="#+id/adapter_textview_column1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<TextView android:id="#+id/adapter_textview_column2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<TextView android:id="#+id/adapter_textview_column3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<CheckBox
android:id="#+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:gravity="center" />
</LinearLayout>

Categories

Resources