(First of all sorry my bad english)
I am doing an app about routes in my town, is like a project of my grade, and I have it done it all but I don't know what is the problem..
My problem is that the ListView that I made from a ViewHolder it doesn't show up when I start the app.
My code is this:
MainActivity:
public class RutasActivity extends AppCompatActivity {
private static final String LOGO = "";
ImageButton btnImgAtras;
private ListView lv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rutas);
lv = (ListView)findViewById(R.id.lvRutas);
RutasParser parser = new RutasParser(this);
if(parser.parse()) {
Ruta[] rutas = parser.getRutas();
RutaAdapter adapter = new RutaAdapter(this, rutas);
lv.setAdapter(adapter);
Toast.makeText(this, "Enseñando", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "No se pudieron obtener los datos de los países", Toast.LENGTH_SHORT).show();
}
btnImgAtras = (ImageButton)findViewById(R.id.imgBtnAtras);
btnImgAtras.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(RutasActivity.this, MainActivity.class);
startActivity(i);
}
});
}
}
Activity Layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RutasActivity"
>
<ImageView
android:layout_width="45dp"
android:layout_height="44dp"
app:srcCompat="#drawable/escudoazulsinfondo"
android:id="#+id/imageView5"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:contentDescription="" />
<TextView
android:text="#string/Rutas_Javea"
android:textSize="20sp"
android:textColor="#color/Blacky"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_marginTop="32dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp" />
<ImageButton
android:layout_width="32dp"
android:layout_height="32dp"
app:srcCompat="#drawable/atras"
android:id="#+id/imgBtnAtras"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
android:background="#android:color/transparent"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" />
<ListView
android:layout_width="312dp"
android:layout_height="358dp"
android:id="#+id/lvRutas"
android:layout_marginStart="24dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="24dp"
android:layout_marginEnd="24dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="24dp"
app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="24dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent" >
</ListView>
<ImageView
android:layout_width="105dp"
android:layout_height="36dp"
app:srcCompat="#drawable/depturismenofondo"
android:id="#+id/imageView6"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"
tools:ignore="ContentDescription" />
</android.support.constraint.ConstraintLayout>
Then, my AdapterView:
public class RutaAdapter extends ArrayAdapter<Ruta> {
Ruta[] rutas;
public RutaAdapter(Context context, Ruta[]rutas) {
super(context, R.layout.listitem_ruta, rutas);
this.rutas = rutas;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View item = convertView;
ViewHolder viewHolder;
if(item == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
item = inflater.inflate(R.layout.listitem_ruta, null);
viewHolder = new ViewHolder();
viewHolder.vhKm = (TextView) item.findViewById(R.id.listKm);
viewHolder.vhNombreRuta = (TextView) item.findViewById(R.id.listNombre);
viewHolder.vhDesnivel = (TextView) item.findViewById(R.id.listDesnivel);
viewHolder.vhDificultad = (TextView) item.findViewById(R.id.listDificultad);
viewHolder.vhTiempoTotal = (TextView) item.findViewById(R.id.listTiempo);
item.setTag(viewHolder);
} else {
viewHolder = (ViewHolder)item.getTag();
}
viewHolder.vhKm.setText(String.valueOf(rutas[position].getDistancia()));
viewHolder.vhNombreRuta.setText(rutas[position].getNombre());
viewHolder.vhDificultad.setText(rutas[position].getNivel_dificultad());
viewHolder.vhTiempoTotal.setText(rutas[position].getTiempo_efectivo());
viewHolder.vhDesnivel.setText(String.valueOf(rutas[position].getDesnivel_acumulado_ascenso()));
return item;
}
static class ViewHolder {
TextView vhNombreRuta;
TextView vhKm;
TextView vhDificultad;
TextView vhTiempoTotal;
TextView vhDesnivel;
}
}
My parser:
public class RutasParser {
private Ruta[] rutas;
private InputStream rutasFile;
public RutasParser(Context c) {
this.rutasFile = c.getResources().openRawResource(R.raw.rutas);
}
public boolean parse() {
boolean parsed = false;
rutas = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(rutasFile);
Element root = dom.getDocumentElement();
NodeList items = root.getElementsByTagName("country");
rutas = new Ruta[items.getLength()];
for (int i = 0; i < items.getLength(); i++) {
Node item = items.item(i);
int rutaId = Integer.parseInt(item.getAttributes().getNamedItem("code").getNodeValue());
String rutaNombre = item.getAttributes().getNamedItem("name").getNodeValue();
String rutaDescrip = item.getAttributes().getNamedItem("description").getNodeValue();
double rutaDistance = Double.valueOf(item.getAttributes().getNamedItem("distance").getNodeValue());
String rutaHora = item.getAttributes().getNamedItem("horas").getNodeValue();
String rutaDif = item.getAttributes().getNamedItem("dificultad").getNodeValue();
int rutaElev = Integer.valueOf(item.getAttributes().getNamedItem("elevacion").getNodeValue());
rutas[i] = new Ruta(rutaId, rutaNombre, rutaDescrip, rutaDistance, rutaDif, rutaHora, rutaElev);
}
parsed = true;
} catch (ParserConfigurationException pce) {
Log.e("CountryParser", "ParserConfigurationException: "+pce.getLocalizedMessage());
} catch (Exception e) {
Log.e("CountryParser", "Unknown Exception: "+e.getLocalizedMessage());
}
return parsed;
}
public Ruta[] getRutas() {
return this.rutas;
}
}
And the ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00.00km"
android:textSize="30sp"
android:id="#+id/listKm"
android:layout_gravity="center_horizontal|center_vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:paddingLeft="3dp"
android:paddingStart="3dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="nombre de ruta"
android:id="#+id/listNombre"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listDificultad"
android:text="dificultad"
android:paddingRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listTiempo"
android:text="000000"
android:paddingRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listDesnivel"
android:text="000000"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
At first place I don´t see any error but it doesn´t show up in my app..
If you can help me, I would be grateful..
Thanks
Photo of what I tell you
Related
I have ListView and my own adapter. ListView item consists of TextView, icon image and image "trash can"(simply "trash"). The problem is when i click on any item it should be deleted but in fact the last item of ListView disappears. I checked ArrayList and the item I clicked on is deleted from there.
Also when i try to add new item the program just restore previous items and if all initial items are displayed and i try to add new the program crashes. Although in ArrayList items are added correctly.
Activity code
public class MyItemsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_items);
myItemsList = findViewById(R.id.ListOfMyItems);
myItemsAdapter.arrayList.add(new MyItems("Keys", R.drawable.plus));
myItemsAdapter.arrayList.add(new MyItems("Wallet", R.drawable.plus));
myItemsAdapter.arrayList.add(new MyItems("Physics", R.drawable.plus));
myItemsAdapter.arrayList.add(new MyItems("umovnyy vasyl", R.drawable.plus));
myItemsAdapter.arrayList.add(new MyItems("Smartphone)", R.drawable.plus));
for (int i = 0; i<100; i++){
arrayList.add(new MyItems("Max)", R.drawable.plus));
}
myItemsList.addFooterView(new ImageView(this));
myItemsList.addHeaderView(new ImageView(this));
myItemsList.setAdapter(myItemsAdapter);
for (int i = 0; i<100; i++){
myItemsAdapter.arrayList.remove((5));
}
arrayList.add(new MyItems("Maxx)", R.drawable.plus));
myItemsAdapter.notifyDataSetChanged();
myItemsAdapter.notifyDataSetInvalidated();
myItemsList.setOnItemClickListener((parent, view, position, id) -> {
Toast.makeText(getApplicationContext(),
"Click ListItem Number " + position, Toast.LENGTH_SHORT)
.show();
myItemsAdapter.arrayList.remove((position-1));
myItemsAdapter.notifyDataSetChanged();
myItemsList.invalidateViews();
myItemsAdapter.notifyDataSetInvalidated();
});
}
ListView myItemsList;
ArrayList<MyItems> arrayList = new ArrayList<>();
MyItemsAdapter myItemsAdapter = new MyItemsAdapter(MyItemsActivity.this, arrayList);
public void addNewItem(View view) {
AlertDialog.Builder dialog = new AlertDialog.Builder(MyItemsActivity.this);
dialog.setView(R.layout.add_new_item);
AlertDialog alertDialog = dialog.create();
ListView a = alertDialog.getListView();
alertDialog.show();
myItemsList.invalidateViews();
}
public void addNewItemButtonClicked(View view){
LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.layout.add_new_item, null);
EditText nameOfItem = v.findViewById(R.id.nameOfItem);
arrayList.add(new MyItems(nameOfItem.getText().toString(), R.drawable.forwardbutton));
myItemsAdapter.notifyDataSetChanged();
myItemsAdapter.notifyDataSetInvalidated();
}
public void notificationClicked(View view){
Toast.makeText(getApplicationContext(),
"Notification clicked", Toast.LENGTH_SHORT)
.show();
}
public void openMenu(View view) {
Intent intent = new Intent(getBaseContext(), MenuActivity.class);
startActivity(intent);
}
}
Adapter
class MyItemsAdapter extends BaseAdapter {
ArrayList<MyItems> arrayList;
Context context;
public MyItemsAdapter(Context context, ArrayList<MyItems> arrayList) {
this.arrayList=arrayList;
this.context=context;
}
#Override
public boolean areAllItemsEnabled() {
return false;
}
#Override
public boolean isEnabled(int position) {
return true;
}
#Override
public void registerDataSetObserver(DataSetObserver observer) {
observer.onChanged();
super.registerDataSetObserver(observer);
}
#Override
public void unregisterDataSetObserver(DataSetObserver observer) {
super.unregisterDataSetObserver(observer);
observer.onInvalidated();
}
#Override
public int getCount() {
return arrayList.size();
}
#Override
public MyItems getItem(int position) {
return arrayList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final MyItems myItems = arrayList.get(position);
if(convertView == null) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
convertView = layoutInflater.inflate(R.layout.example_of_list_of_items, parent, false);
TextView nameOfItem = convertView.findViewById(R.id.exampleTextView);
ImageView itemCircle = convertView.findViewById(R.id.exampleImageViewIcon);
ImageView trash = convertView.findViewById(R.id.exampleImageViewTrash);
nameOfItem.setText(myItems.itemName);
itemCircle.setImageResource(myItems.itemImage);
trash.setImageResource(R.drawable.trash);
trash.setOnClickListener(v -> {
Toast.makeText(context, "lol "+position, Toast.LENGTH_SHORT).show();
arrayList.remove(position);
notifyDataSetChanged();
notifyDataSetInvalidated();
});
}
return convertView;
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public int getViewTypeCount() {
return arrayList.size();
}
#Override
public boolean isEmpty() {
return false;
}
}
MyItems code
class MyItems {
String itemName;
int itemImage;
public MyItems(String itemName, int image) {
this.itemName = itemName;
this.itemImage = image;
}
}
Example of item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/exampleTextView"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="85dp"
android:fadingEdge="horizontal|vertical"
android:layoutDirection="inherit"
android:lineSpacingExtra="14sp"
android:text="TextView"
android:textAlignment="textStart"
android:textColor="#000000"
android:textSize="20sp"
app:autoSizeMaxTextSize="20sp"
app:autoSizeMinTextSize="8sp"
app:layout_constraintEnd_toStartOf="#+id/exampleImageViewTrash"
app:layout_constraintStart_toEndOf="#+id/exampleImageViewLeft"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/exampleImageViewLeft"
android:layout_width="25dp"
android:layout_height="23dp"
android:layout_marginStart="32dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher_round" />
<ImageView
android:id="#+id/exampleImageViewTrash"
android:layout_width="49dp"
android:layout_height="47dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="20dp"
android:cropToPadding="true"
android:fitsSystemWindows="true"
android:focusableInTouchMode="false"
android:focusable="false"
android:clickable="false"
android:scaleType="centerInside"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/trash" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintGuide_begin="70dp"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Code of main screen
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="99dp">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintGuide_begin="127dp"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/myItemsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/my_items"
android:textColor="#000000"
android:textSize="36sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/menuImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:clickable="true"
android:focusable="true"
android:onClick="openMenu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/menu" />
<ImageView
android:id="#+id/notificationImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:clickable="true"
android:focusable="true"
android:onClick="notificationClicked"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/notification" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/ListOfMyItems"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="100dp"
android:alwaysDrawnWithCache="true"
android:animateLayoutChanges="true"
android:choiceMode="singleChoice"
android:clickable="false"
android:clipToPadding="false"
android:descendantFocusability="beforeDescendants"
android:dividerHeight="1dp"
android:footerDividersEnabled="true"
android:headerDividersEnabled="true"
android:isScrollContainer="true"
android:layoutDirection="ltr"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:listfooter="#android:layout/simple_list_item_1">
</ListView>
<LinearLayout
android:layout_width="409dp"
android:layout_height="70dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:focusable="auto"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ListOfMyItems">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true">
<TextView
android:id="#+id/addNewItemTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="-1dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="70dp"
android:clickable="true"
android:focusable="true"
android:onClick="addNewItem"
android:text="#string/add_new_item"
android:textColor="#000000"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/plusImageView"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/plusImageView"
android:layout_width="67dp"
android:layout_height="74dp"
android:layout_marginStart="56dp"
android:clickable="false"
android:focusable="true"
android:onClick="addNewItem"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/plus" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Code for AlertDialog adding new item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="300dp"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#FFFFFF">
<EditText
android:id="#+id/nameOfItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:ems="10"
android:hint="Enter name"
android:inputType="textPersonName"
android:singleLine="true"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="9dp"
android:background="#android:drawable/btn_default_small"
android:onClick="addNewItemButtonClicked"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/nameOfItem" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Looks like your data is not properly updated inside the Adapter's getView method.
You should try to update the item inside the Adapter when contentView is not null.
For performance reason, there is a pattern called ViewHolder used inside the adapter. Refer to Android listview using ViewHolder for more info. Just create Holder when contentView is null and set the data when it isn't. Hope it helps.
P.S. ListView is considered deprecated. Use RecyclerView instead. It has already built-in ViewHolder pattern and is more flexible
I want a listview in a tabhost. My data is coming from the database. Through retrofit, I am getting 3 records from the database. I am passing these 3 records to the ListView Adapter that I have created. These records are coming till the constructor of Adapter but after that in the getView method only 1 record is accessed 3 times. I am not sure why this is happening.
This is my Post Activity:
public static final ArrayList<WorkProfilePojo> mProfiles = new ArrayList<>();
BaseURL baseURL = new BaseURL();
VendorPostAdapter pAdapter;
ListView mPostList;
public List<WorkProfilePojo> returnedList = new ArrayList<>();
String lv_vendorId = null;
public static String lv_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
lv_vendorId = intent.getStringExtra("lv_vendorId");
Log.e("vendor id", lv_vendorId);
lv_name = intent.getStringExtra("lv_name");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
getRetrofit();
}
private void getRetrofit() {
Retrofit retrofit = new RetrofitObject().getRetrofit();
final WorkProfileforPostTabAPI mProfileAPI =
retrofit.create(WorkProfileforPostTabAPI.class);
final Call<ArrayList<WorkProfilePojo>> mCall =
mProfileAPI.getWork(lv_vendorId);
mCall.enqueue(new Callback<ArrayList<WorkProfilePojo>>() {
#Override
public void onResponse(Call<ArrayList<WorkProfilePojo>> call,
Response<ArrayList<WorkProfilePojo>> response) {
mProfiles.clear();
returnedList = (ArrayList<WorkProfilePojo>)response.body();
WorkProfilePojo wp;
Log.e("Teste2",
returnedList.get(0).getLv_eventSubCategory());
for (int i = 0; i<= returnedList.size()-1; i++){
wp=new WorkProfilePojo();
wp.setLv_vendorWorkId(returnedList.get(i).getLv_vendorWorkId());
wp.setLv_eventSubCategory(returnedList.get(i).getLv_eventSubCategory());
wp.setLv_workDescription(returnedList.get(i).getLv_workDescription());
wp.setLv_numWorkLikes(returnedList.get(i).getLv_numWorkLikes());
wp.setLv_numWorkComments(returnedList.get(i).getLv_numWorkComments());
mProfiles.add(wp);
Log.e("retrofit profile size: ",
String.valueOf(mProfiles.size()));
populateListView(mProfiles);
}
#Override
public void onFailure(Call<ArrayList<WorkProfilePojo>> call,
Throwable t) {
Log.e(TAG, "FAIL");
}
});
}
private void populateListView(ArrayList<WorkProfilePojo> mProfiles) {
mPostList = (ListView) findViewById(R.id.listVPost);
Log.e("func prof size: ", String.valueOf(mProfiles.size()));
pAdapter = new VendorPostAdapter(this, mProfiles, lv_name);
mPostList.setAdapter(pAdapter);
}
This is my Adapter:
public class VendorPostAdapter extends BaseAdapter {
Context context;
ArrayList<WorkProfilePojo> lv_profiles = new ArrayList<>();
String lv_name;
LayoutInflater inflater;
public VendorPostAdapter(Context context, ArrayList<WorkProfilePojo>
lv_profiles, String lv_name){
this.context = context;
this.lv_profiles =lv_profiles;
this.lv_name = lv_name;
Log.e("adapter name", lv_name );
Log.e("adapter workid", lv_profiles.get(0).getLv_vendorWorkId());
Log.e("adapter workid", lv_profiles.get(1).getLv_vendorWorkId());
Log.e("adapter workid", lv_profiles.get(2).getLv_vendorWorkId());
}
private class ViewHolder {
TextView mtxtViewPartnerName;
TextView mtxtViewEventCategory;
TextView mtxtViewDate ;
TextView mtxtViewFillDescription;
GridView mgrdViewPhotos ;
ImageView mimgLike ;
ImageView mimgPostProfilePic ;
ImageView mimgShare ;
ImageView mimgComment ;
ImageView mimgLikeThumb ;
TextView mtxtNoOfLikes ;
TextView mtxtNoOfComments ;
TextView mtxtComments;
}
#Override
public int getCount() {
return lv_profiles.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
inflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.content_post, parent,
false);
holder = new ViewHolder();
holder.mtxtViewPartnerName = (TextView)
convertView.findViewById(R.id.txtViewPartnerName);
holder.mtxtViewEventCategory= (TextView)
convertView.findViewById(R.id.txtViewEventCategory);
holder.mtxtViewDate = (TextView)
convertView.findViewById(R.id.txtViewDate);
holder.mtxtViewFillDescription = (TextView)
convertView.findViewById(R.id.txtViewFillDescription);
holder.mgrdViewPhotos = (GridView)
convertView.findViewById(R.id.grdViewPhotos);
holder.mimgLike = (ImageView)
convertView.findViewById(R.id.imgLike);
holder.mimgPostProfilePic = (ImageView)
convertView.findViewById(R.id.imgPostProfilePic);
holder.mimgShare = (ImageView)
convertView.findViewById(R.id.imgShare);
holder.mimgLikeThumb = (ImageView)
convertView.findViewById(R.id.imgLikeThumb);
holder.mimgComment = (ImageView)
convertView.findViewById(R.id.imgComment);
holder.mtxtNoOfLikes = (TextView)
convertView.findViewById(R.id.txtViewNoOfLikes);
holder.mtxtNoOfComments = (TextView)
convertView.findViewById(R.id.txtViewNoOfComments);
holder.mtxtComments = (TextView)
convertView.findViewById(R.id.txtViewComments);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
final WorkProfilePojo wp = lv_profiles.get(position);
Log.e("getView name", lv_name );
Log.e("getView workid",
lv_profiles.get(position).getLv_vendorWorkId());
holder.mtxtViewPartnerName.setText( lv_name );
holder.mtxtViewEventCategory.setText( wp.getLv_eventSubCategory() );
FormatDate lv_date = new FormatDate();
holder.mtxtViewDate.setText(lv_date.formatDayMonDateYr(wp.getLv_creationDate()));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription());
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription());
holder.mimgLikeThumb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,
VendorWorkLikesActivity.class);
intent.putExtra("lv_workId", wp.getLv_vendorWorkId());
Log.e("postad workid", wp.getLv_vendorWorkId());
context.startActivity(intent);
}
});
holder.mtxtComments.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,
VendorWorkCommentActivity.class);
context.startActivity(intent);
}
});
return convertView;
}
}
This is my activity_post.xml wrapped in relative layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundcolour"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="1"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
/>
</RelativeLayout>
This is my content_post for line item wrapped in relative layout:
<RelativeLayout
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgPostProfilePic"
android:src="#drawable/profileicon"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="#+id/txtViewPartnerName"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_toEndOf="#id/imgPostProfilePic"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:text="partner Name" />
<TextView
android:id="#+id/txtViewManageWork"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:layout_marginTop="5dp"
android:text="Managed" />
<TextView
android:id="#+id/txtViewEventCategory"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="220dp"
android:paddingRight="5dp"
android:layout_marginTop="5dp"
android:text="" />
<TextView
android:id="#+id/txtViewEvent"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_toEndOf="#id/txtViewEventCategory"
android:layout_marginTop="5dp"
android:text="Event" />
<TextView
android:id="#+id/txtViewDate"
style="#style/InputLable"
android:layout_width="100dp"
android:layout_height="25dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
android:text="Date" />
<TextView
android:id="#+id/txtViewDescription"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="80dp"
android:text="Work Description" />
<TextView
android:id="#+id/txtViewFillDescription"
style="#style/InputLable"
android:layout_width="330dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:text="XYZ" />
<TextView
android:id="#+id/txtViewPhotos"
style="#style/Keywords"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="130dp"
android:text="Photos" />
<GridView
android:id="#+id/grdViewPhotos"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:numColumns="auto_fit"
android:layout_below="#id/txtViewPhotos">
</GridView>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="#+id/divider"
android:background="#color/colorDarkGray"
android:layout_below="#id/grdViewPhotos"
android:layout_weight="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dividerlayout"
android:orientation="horizontal"
android:layout_below="#id/divider"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ImageView
android:id="#+id/imgLikeThumb"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_below="#id/grdViewPhotos"
android:clickable="true"
android:src="#drawable/likethumb" />
<TextView
android:id="#+id/txtViewNoOfLikes"
style="#style/InputLable"
android:layout_width="30dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:textAlignment="center"
android:layout_marginTop="5dp"
android:text="0" />
<TextView
android:id="#+id/txtViewNoOfComments"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="5dp"
android:textAlignment="center"
android:text="0" />
<TextView
android:id="#+id/txtViewComments"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:text="Comments" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="#+id/divider1"
android:background="#color/colorDarkGray"
android:layout_below="#id/dividerlayout"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/dividerlayout1"
android:layout_below="#id/dividerlayout"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/imgLike"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#id/divider1"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/likeicon2" />
<TextView
android:id="#+id/txtViewLike"
style="#style/InputLable"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Likes" />
<ImageView
android:id="#+id/imgShare"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="60dp"
android:layout_below="#id/divider1"
android:layout_centerInParent="true"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/shareicon3" />
<TextView
android:id="#+id/txtViewShare"
style="#style/InputLable"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Share" />
<ImageView
android:id="#+id/imgComment"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="45dp"
android:layout_below="#id/divider1"
android:layout_marginTop="5dp"
android:clickable="true"
android:src="#drawable/commenticon" />
<TextView
android:id="#+id/txtViewComment"
style="#style/InputLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="#id/divider1"
android:text="Comment" />
</LinearLayout>
</RelativeLayout>
From retrofit results, I am getting 3 records from database:
func workid:: W00000000000013
func workid:: W00000000000014
func workid:: W00000000000015
But in getView() method I am getting only 1 record coming 3 times:
Likesad name: W00000000000013
Likesad name: W00000000000013
Likesad name: W00000000000013
holder.mtxtViewDate.setText(lv_date.formatDayMonDateYr(wp.getLv_creationDate(getPostion())));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription(getPostion()));
holder.mtxtViewFillDescription.setText(wp.getLv_workDescription(getPostion()));
This Might work.
I'm implementing a ListView and on quick scrolling in large lists this glitch occurs. I am using ViewHolder Pattern
[![UI Glitch in ListView][1]][1]
[1]:
getView :
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(this.getContext())
.inflate(mResource, parent, false);
viewHolder = new ViewHolder();
viewHolder.titleView = (TextView) convertView.findViewById(R.id.sheet_name_text_view);
viewHolder.rowsCount = (TextView) convertView.findViewById(R.id.rows_count_text_view);
viewHolder.selectMessage = (TextView) convertView.findViewById(R.id.row_info_text);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final ImportedTable item = getItem(position);
if (item != null) {
viewHolder.titleView.setText(item.getTableName());
int columnsCount = 0;
for (boolean isSelected : item.getSelectedColumns()) {
if (isSelected) {
columnsCount++;
}
}
viewHolder.rowsCount.setText(context.getString(R.string.label_rowscounttext, (item.getRecordsCount() - item.getHeaderRow()), columnsCount));
}
final CheckBox isSelectedForImport = (CheckBox) convertView.findViewById(R.id.import_table_list_toggle_button);
RelativeLayout checkboxLayout = (RelativeLayout) convertView.findViewById(R.id.import_table_list_toggle_layout);
checkboxLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
isSelectedForImport.performClick();
}
});
final TextView selectMessage = (TextView) convertView.findViewById(R.id.row_info_text);
isSelectedForImport.setChecked(item.isSelected());
if (!isSelectedForImport.isChecked()) {
convertView.setClickable(true);
viewHolder.titleView.setTextColor(Color.parseColor("#8A000000"));
} else {
convertView.setClickable(false); viewHolder.titleView.setTextColor(Color.parseColor("#DE000000"));
}
isSelectedForImport.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((ImportActivity) context).getNewApplication().hasChildren(item.getSheetId(), item.getTableId()) && !isSelectedForImport.isChecked()) {
isSelectedForImport.setChecked(true);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
final AlertDialog dialog;
builder.setMessage(context.getString(R.string.importapplication_appscreen_label_lookupwarningmessage));
builder.setPositiveButton(context.getString(R.string.ui_label_continue), new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < item.getColumnType().size(); i++) {
removeLookups(item.getSheetId(), item.getTableId(), i);
}
isSelectedForImport.setChecked(false);
item.setSelected(false);
dialog.dismiss();
}
});
builder.setNegativeButton(context.getString(R.string.ui_label_dontcontinue), new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog = builder.show();
notifyDataSetChanged();
} else if (!isSelectedForImport.isChecked()) {
item.setSelected(isSelectedForImport.isChecked());
notifyDataSetChanged();
} else {
if (isSelectedForImport.isChecked()) {
for (int i = 0; i < item.getColumnType().size(); i++) {
if (item.getSelectedColumns().get(i) && item.getColumnType().get(i).equals("SINGLE_LOOKUP")) {
enableParents(item.getSheetId(), item.getTableId(), i);
}
}
notifyDataSetChanged();
}
item.setSelected(isSelectedForImport.isChecked());
}
mCallback.onTableSelectionToggle();
}
});
if (((ImportActivity) context).getNewApplication().hasChildren(item.getSheetId(), item.getTableId())) {
Set<String> children = ((ImportActivity) context).getNewApplication().getChildTableNames(item.getSheetId(), item.getTableId());
Iterator<String> childIterator = children.iterator();
String childrenString = childIterator.next();
while (childIterator.hasNext()) {
childrenString += ", ";
childrenString += childIterator.next();
}
selectMessage.setText(context.getString(R.string.label_importlookupchildrentext) +" "+ childrenString);
selectMessage.setVisibility(View.VISIBLE);
} else {
selectMessage.setVisibility(View.GONE);
}
return convertView;
}
This does not occur all the time, and it doesn't occur for small lists. I have no other common problems described in other posts here (as long as this glitch doesn't occur, all views work correctly, and are in proper order).
XML Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sheet_row_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingLeft="16dp">
<TextView
android:id="#+id/sheet_name_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:textColor="#DE000000"
android:textSize="16sp"
tools:text="Sheet Name" />
<TextView
android:id="#+id/rows_count_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#8A000000"
android:textSize="14sp"
tools:text="Rows : 3" />
<TextView
android:id="#+id/row_info_text"
android:textSize="12sp"
android:layout_width="match_parent"
android:ellipsize="end"
android:maxLines="1"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:visibility="gone"
tools:visibility="gone"
tools:text="This form is looked up by "/>
</LinearLayout>
<RelativeLayout
android:id="#+id/import_table_list_toggle_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="19dp"
android:paddingRight="19dp"
android:layout_alignParentRight="true">
<CheckBox
android:id="#+id/import_table_list_toggle_button"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:clickable="true"
android:paddingBottom="24dp"
android:paddingTop="24dp" />
</RelativeLayout>
As I mention problem is RelativeLayout layout.
try this...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sheet_row_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal"
android:weightSum="10">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingLeft="16dp">
<TextView
android:id="#+id/sheet_name_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:textColor="#DE000000"
android:textSize="16sp"
tools:text="Sheet Name"/>
<TextView
android:id="#+id/rows_count_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#8A000000"
android:textSize="14sp"
tools:text="Rows : 3"/>
<TextView
android:id="#+id/row_info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="12sp"
android:visibility="gone"
tools:text="This form is looked up by "
tools:visibility="gone"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/import_table_list_toggle_layout"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingLeft="19dp"
android:paddingRight="19dp">
<CheckBox
android:id="#+id/import_table_list_toggle_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:paddingBottom="24dp"
android:paddingTop="24dp"/>
</RelativeLayout>
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
I have a fragment with a foldingcell view
here is the mainfragment -
public class FriendFragmentMain extends Fragment {
private static final String TAG = FriendFragmentMain.class.getSimpleName();
private FriendsCellListAdapter friendsCellListAdapter;
private List<FriendsItem> friendsItems;
private String URL_FRIEND="http://212.224.76.127/friends/friends.json";
private FragmentActivity fragmentActivity;
private Activity mActivity;
private ListView friendsListView;
public static FriendFragmentMain newInstance(){
FriendFragmentMain friendFragmentMain = new FriendFragmentMain();
return friendFragmentMain;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.friend_fragment_main, container, false);
friendsListView = (ListView) getActivity().findViewById(R.id.friend_super_list);
friendsItems = new ArrayList<>();
friendsCellListAdapter = new FriendsCellListAdapter(mActivity, friendsItems);
friendsListView.setAdapter(friendsCellListAdapter);
friendsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
((FoldingCell) view).toggle(false);
friendsCellListAdapter.registerToggle(pos);
}
});
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Cache.Entry entry = cache.get(URL_FRIEND);
if (entry != null){
try {
String data = new String(entry.data, "UTF-8");
try {
parseJsonFriend(new JSONObject(data));
} catch (JSONException e){
e.printStackTrace();
}
}catch (UnsupportedEncodingException e){
e.printStackTrace();
}
} else {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
URL_FRIEND, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response:" + response.toString());
if (response != null) {
parseJsonFriend(response);
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "ERROR:" + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(jsonObjectRequest);
}
return view;
}
private void parseJsonFriend(JSONObject response){
try {
JSONArray friendArray = response.getJSONArray("friends");
for (int i =0; i < friendArray.length(); i++){
JSONObject friendObj = (JSONObject) friendArray.get(i);
FriendsItem item = new FriendsItem();
item.setId(friendObj.getInt("id"));
item.setName(friendObj.getString("name"));
item.setProfilePic(friendObj.getString("profilePic"));
item.setBackgroundImage(friendObj.getString("backgroundImage"));
item.setStatus(friendObj.getString("status"));
item.setWork(friendObj.getString("work"));
item.setLocation(friendObj.getString("location"));
String friendUrl = friendObj.isNull("website")? null : friendObj
.getString("website");
item.setWebsite(friendUrl);
friendsItems.add(item);
}
friendsCellListAdapter.notifyDataSetChanged();
} catch (JSONException e){
e.printStackTrace();
}
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = activity;
}
}
the base adapter looks like this -
public class FriendsCellListAdapter extends BaseAdapter{
private HashSet<Integer> unfoldedIndexes = new HashSet<>();
private View.OnClickListener defaultMessageButton;
private View.OnClickListener defaultViewProfileButton;
private Activity activity;
private Context context;
private LayoutInflater inflater;
private List<FriendsItem> friendsItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public FriendsCellListAdapter(Activity activity, List<FriendsItem> friendsItems){
this.activity = activity;
this.friendsItems = friendsItems;
}
#Override
public int getCount() {
return friendsItems.size();
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public Object getItem(int position) {
return friendsItems.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
if (inflater==null)
inflater = (LayoutInflater)activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FriendsItem item = friendsItems.get(position);
FoldingCell cell = (FoldingCell) convertView;
ViewHolder viewHoler;
if (cell == null){
viewHoler = new ViewHolder();
cell = (FoldingCell) inflater.inflate(R.layout.friends_cell, parent, false);
viewHoler.profilePic = (NetworkImageView) cell.findViewById(R.id.friends_profile_pic);
viewHoler.clientName = (LoginTextView) cell.findViewById(R.id.client_name);
viewHoler.friendStatus = (LoginTextView) cell.findViewById(R.id.friend_status);
viewHoler.backgroundImage = (NetworkImageView) cell.findViewById(R.id.friend_background_image);
viewHoler.friendAvatar = (NetworkImageView) cell.findViewById(R.id.friends_avatar);
viewHoler.friendName = (LoginTextView) cell.findViewById(R.id.friend_name);
viewHoler.friendLocation = (LoginTextView) cell.findViewById(R.id.friend_location);
viewHoler.friendURL = (LoginTextView) cell.findViewById(R.id.friend_url);
viewHoler.friendWork = (LoginTextView) cell.findViewById(R.id.friend_work);
cell.setTag(viewHoler);
} else {
if (unfoldedIndexes.contains(position)){
cell.unfold(true);
} else {
cell.fold(true);
}
viewHoler = (ViewHolder) cell.getTag();
}
viewHoler.clientName.setText(item.getName());
viewHoler.friendName.setText(item.getName());
//chech for empty status
if (!TextUtils.isEmpty(item.getStatus())){
viewHoler.friendStatus.setText(item.getStatus());
viewHoler.friendStatus.setVisibility(View.VISIBLE);
} else {
viewHoler.friendStatus.setVisibility(View.GONE);
}
//check for empty location
if (!TextUtils.isEmpty(item.getLocation())){
viewHoler.friendLocation.setText(item.getLocation());
viewHoler.friendLocation.setVisibility(View.VISIBLE);
} else {
viewHoler.friendLocation.setVisibility(View.GONE);
}
//check for null url
if (item.getWebsite() != null){
viewHoler.friendURL.setText(Html.fromHtml("" + item.getWebsite()+""));
viewHoler.friendURL.setMovementMethod(LinkMovementMethod.getInstance());
viewHoler.friendURL.setVisibility(View.VISIBLE);
} else {
viewHoler.friendURL.setVisibility(View.GONE);
}
//check for empty work
if (!TextUtils.isEmpty(item.getWork())){
viewHoler.friendWork.setText(item.getWork());
viewHoler.friendWork.setVisibility(View.VISIBLE);
}else {
viewHoler.friendWork.setVisibility(View.GONE);
}
//profile pic
viewHoler.profilePic.setImageUrl(item.getProfilePic(), imageLoader);
viewHoler.friendAvatar.setImageUrl(item.getProfilePic(), imageLoader);
//background image
viewHoler.backgroundImage.setImageUrl(item.getBackgroundImage(), imageLoader);
return convertView;
}
public void registerToggle(int position){
if (unfoldedIndexes.contains(position))
registerFold(position);
else
registerUnfold(position);
}
public void registerFold(int position){unfoldedIndexes.remove(position);}
public void registerUnfold(int position){
unfoldedIndexes.add(position);
}
private class ViewHolder{
NetworkImageView profilePic;
LoginTextView clientName;
LoginTextView friendStatus;
NetworkImageView backgroundImage;
NetworkImageView friendAvatar;
LoginTextView friendName;
LoginTextView friendLocation;
LoginTextView friendURL;
LoginTextView friendWork;
}
}
now when i run it it throws -
Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at com.evolustudios.askin.askin.src.fragments.FriendFragmentMain.onCreateView(FriendFragmentMain.java:60)
this error. i am unable to find out why its throwing a null object? can anyone throw a light on why its showing null object.
the views are here- friends_cell
<com.ramotion.foldingcell.FoldingCell xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
xmlns:folding-cell="http://schemas.android.com/apk/res-auto"
folding-cell:additionalFlipsCount="2"
folding-cell:animationDuration="1300"
folding-cell:backSideColor="#color/bgBackSideColor">
<include layout="#layout/friends_content_layout"/>
<include layout="#layout/friends_cell_title_layout"/>
</com.ramotion.foldingcell.FoldingCell>
friends_cell_title_layout -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<!--LEFT Part -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_weight="3"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp"
android:background="#color/feed_item_border">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/friends_profile_pic"
android:scaleType="fitCenter"/>
</RelativeLayout>
<!--RIGHT Part-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingBottom="20dp"
android:paddingEnd="20dp"
android:paddingStart="15dp"
android:paddingTop="20dp"
android:background="#color/feed_item_border">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:id="#+id/title_from_to_dots"
android:layout_marginEnd="10dp"
android:src="#drawable/from_to_purple"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/client_name"
android:layout_alignTop="#+id/title_from_to_dots"
android:layout_marginTop="-5dp"
android:layout_toEndOf="#+id/title_from_to_dots"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="#android:color/holo_blue_dark"
android:textSize="16sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/friend_profile_divider"
android:layout_below="#+id/client_name"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="#+id/title_from_to_dots"
android:src="#color/contentDividerLine"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_status"
android:layout_below="#+id/friend_profile_divider"
android:layout_toEndOf="#+id/title_from_to_dots"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="#android:color/holo_blue_dark"
android:textSize="16sp"/>
</RelativeLayout>
and friend_content_layout -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<!--Content header line-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/text_password"
android:paddingBottom="7dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="7dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/menu_icon"/>
</RelativeLayout>
<!--Content header Image-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/friend_background_image"
android:scaleType="centerCrop"/>
</RelativeLayout>
<!--Content body layout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="6dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="9dp">
<!--avatar and name-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.android.volley.toolbox.NetworkImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friends_avatar"
android:layout_alignParentStart="true"
android:layout_marginBottom="5dp"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_name"
android:layout_alignTop="#+id/friends_avatar"
android:layout_marginBottom="2dp"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/friends_avatar"
android:textColor="#color/mainTextColor"
android:textSize="18sp"
android:textStyle="bold"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_location"
android:layout_alignStart="#+id/friend_name"
android:layout_marginBottom="-2dp"
android:layout_marginStart="3dp"
android:layout_below="#+id/friend_name"
android:textColor="#a9a9a9"
android:textSize="12sp"/>
</RelativeLayout>
<!--Divider Line-->
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="6dp"
android:layout_marginTop="9dp"
android:src="#color/contentDividerLine"/>
<!--Address Part-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/url_badge"
android:textColor="#a9a9a9"
android:layout_alignParentStart="true"
android:text="WEBSITE"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_url"
android:layout_alignStart="#+id/url_badge"
android:layout_below="#+id/url_badge"
android:textColor="#color/mainTextColor"
android:textSize="18sp"
android:textStyle="bold"/>
</RelativeLayout>
</LinearLayout>
<!--Divider Line-->
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="6dp"
android:layout_marginTop="7dp"
android:src="#color/contentDividerLine"/>
<!--Work Part-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/work_badge"
android:textColor="#a9a9a9"
android:layout_alignParentStart="true"
android:text="WORK"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/friend_work"
android:layout_alignStart="#+id/work_badge"
android:layout_below="#+id/work_badge"
android:textColor="#color/mainTextColor"
android:textSize="18sp"
android:textStyle="bold"/>
</RelativeLayout>
</LinearLayout>
<!--Buttons-->
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/friend_send_message"
android:layout_marginTop="16dp"
android:background="#color/btnRequest"
android:padding="10dp"
android:text="Send Message"
android:textAlignment="center"
android:textColor="#color/mainTextColor"
android:textSize="20sp"/>
<com.evolustudios.askin.askin.src.customfonts.LoginTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/friend_view_profile"
android:layout_marginTop="16dp"
android:background="#color/btnRequest"
android:padding="10dp"
android:text="View Profile"
android:textAlignment="center"
android:textColor="#color/mainTextColor"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
Initialize friendsItems before passing it to friendsCellListAdapter
friendsItems = new ArrayList<FriendsItem>(); // add this line
friendsCellListAdapter = new FriendsCellListAdapter(mActivity, friendsItems);
friendsListView.setAdapter(friendsCellListAdapter);
I am simply trying to show a fragments recyclerView inside it's parent activity. The data is there but nothing is showing up. Any thoughts? Here is PagerAdapter, parent and fragment classes with xmls so that all the parts are available to see. I want the RV to fit right here between the CardView and comment line. Thanks for any help!
PagerAdapter
public class DropPagerAdapter extends FragmentPagerAdapter{
final int PAGE_COUNT = 2;
private String tabTitles[] = new String[] { "Comments", "Riples"};
private Context context;
public DropPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
return CommentFragment.newInstance(position + 1);
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}
Fragment.java
public class CommentFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
private String mDropObjectId;
private String mAuthorId;
private String mAuthorRank;
private String mAuthorName;
private String mAuthorFacebookId;
private String mDropDescription;
private String mRipleCount;
private String mCommentCount;
private Date mCreatedAt;
private String mTabName;
private RecyclerView mRecyclerView;
private TextView mViewDropEmptyView;
private ArrayList<CommentItem> mCommentList;
private CommentAdapter mCommentAdapter;
public static CommentFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
CommentFragment fragment = new CommentFragment();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_comment, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.comment_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mViewDropEmptyView = (TextView) view.findViewById(R.id.comment_empty_view);
Intent intent = getActivity().getIntent();
mDropObjectId = intent.getStringExtra("dropObjectId");
mAuthorId = intent.getStringExtra("authorId");
mAuthorRank = intent.getStringExtra("authorRank");
mAuthorName = intent.getStringExtra("commenterName");
mAuthorFacebookId = intent.getStringExtra("authorFacebookId");
mDropDescription = intent.getStringExtra("dropDescription");
mRipleCount = intent.getStringExtra("ripleCount");
mCommentCount = intent.getStringExtra("commentCount");
mCreatedAt = (Date) intent.getSerializableExtra("createdAt");
mTabName = intent.getStringExtra("mTabName");
loadCommentsFromParse();
return view;
}
public void loadCommentsFromParse() {
final ArrayList<CommentItem> commentList = new ArrayList<>();
final ParseQuery<ParseObject> query = ParseQuery.getQuery("Comments");
query.whereEqualTo("dropId", mDropObjectId);
query.orderByDescending("createdAt");
query.include("commenterPointer");
// query.setLimit(25);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e != null) {
Log.d("KEVIN", "error error");
} else {
for (int i = 0; i < list.size(); i++) {
final CommentItem commentItem = new CommentItem();
ParseObject commenterData = (ParseObject) list.get(i).get("commenterPointer");
//Commenter data////////////////////////////////////////////////////////////
ParseFile profilePicture = (ParseFile) commenterData.get("parseProfilePicture");
if (profilePicture != null) {
profilePicture.getDataInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
// Bitmap resized = Bitmap.createScaledBitmap(bmp, 100, 100, true);
commentItem.setParseProfilePicture(bmp);
updateRecyclerView(commentList);
}
}
});
}
//CommenterId
commentItem.setCommenterId(commenterData.getObjectId());
//Commenter Name
commentItem.setCommenterName((String) commenterData.get("displayName"));
//Rank
commentItem.setCommenterRank((String) commenterData.get("userRank"));
//Comment Data/////////////////////////////////////////////////////////////
// DropId
commentItem.setDropId(list.get(i).getString("dropId"));
//Comment
commentItem.setCommentText(list.get(i).getString("commentText"));
//Date
commentItem.setCreatedAt(list.get(i).getCreatedAt());
commentList.add(commentItem);
}
Log.i("KEVIN", "Comment list size: " + commentList.size());
}
}
});
}
private void updateRecyclerView(ArrayList<CommentItem> comments) {
if (comments.isEmpty()) {
mRecyclerView.setVisibility(View.GONE);
mViewDropEmptyView.setVisibility(View.VISIBLE);
}
else {
mRecyclerView.setVisibility(View.VISIBLE);
mViewDropEmptyView.setVisibility(View.GONE);
}
mCommentAdapter = new CommentAdapter(getActivity(), comments);
ScaleInAnimationAdapter scaleAdapter = new ScaleInAnimationAdapter(mCommentAdapter);
mRecyclerView.setAdapter(new AlphaInAnimationAdapter(scaleAdapter));
mRecyclerView.setAdapter(mCommentAdapter);
}
}
Fragment XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/comment_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Primary_Background_Color"
/>
<TextView
android:id="#+id/comment_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal"
android:visibility="visible"
android:text="Post a comment on this Drop!"
android:textSize="18sp"
android:textStyle="italic"
android:foregroundGravity="center"
android:paddingBottom="200dp"
android:textAlignment="center"/>
Parent XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:background="#color/Primary_Background_Color"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:id="#+id/card_view_drop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#FFFFFF"
card_view:cardPreventCornerOverlap="false"
>
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_gravity="bottom"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white"/>
<RelativeLayout
android:id="#+id/click_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:background="#drawable/custom_bg">
<android.support.v7.widget.Toolbar
android:id="#+id/trickle_card_tool_bar"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#BBDEFB"
/>
<ImageView
android:id="#+id/profile_picture"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_default"
android:background="#drawable/custom_bg"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/profile_picture"
android:width="50dp"
android:text="Kevin Hodges"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp"
android:textColor="#000000"
android:singleLine="true"
android:layout_alignTop="#+id/profile_picture"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_toStartOf="#+id/menu_button"
android:layout_toLeftOf="#+id/menu_button"
android:background="#drawable/custom_bg_blue"
android:clickable="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/comment_created_at"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="September 18, 2015 # 3:32 p.m."
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="10sp"
android:singleLine="true"
android:background="#drawable/custom_bg"
android:gravity="left"
android:layout_alignBottom="#+id/profile_picture"
android:layout_alignRight="#+id/menu_button"
android:layout_alignEnd="#+id/menu_button"
android:layout_toRightOf="#+id/profile_picture"
android:layout_marginLeft="8dp"
/>
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:focusable="false"
android:maxLines="5"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="false"
android:text="Description"
android:layout_below="#+id/profile_picture"
android:textColor="#color/PrimaryText"
android:textSize="14sp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="32dp"
android:background="#drawable/custom_bg"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/menu_button"
android:layout_marginLeft="8dp"
android:src="#drawable/menu_svg"
android:layout_alignBottom="#+id/trickle_card_tool_bar"
android:layout_marginBottom="16dp"
android:background="#drawable/custom_bg_blue"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginRight="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""Mother Teresa""
android:id="#+id/author_rank"
android:textSize="14sp"
android:singleLine="false"
android:gravity="left|center_vertical|center_horizontal"
android:layout_alignLeft="#+id/name"
android:layout_alignStart="#+id/name"
android:textStyle="italic"
android:layout_below="#+id/name"
android:layout_alignBottom="#+id/trickle_card_tool_bar"
android:textColor="#7d000000"
android:layout_toStartOf="#+id/menu_button"
android:layout_marginTop="-4dp"
android:layout_toLeftOf="#+id/menu_button"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<AutoCompleteTextView
android:id="#+id/enter_comment_text"
android:layout_width="235dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/button_post_comment"
android:layout_toLeftOf="#+id/button_post_comment"
android:layout_toRightOf="#+id/post_comment_profile_picture"
android:layout_toStartOf="#+id/button_post_comment"
android:background="#ffffff"
android:hint="#string/write_comment_hint"
android:inputType="textCapSentences|textAutoComplete|textAutoCorrect|text"
android:maxLength="250"
android:paddingLeft="8dp"/>
<ImageView
android:id="#+id/post_comment_profile_picture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:foregroundGravity="center_vertical"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_default"/>
<Button
android:id="#+id/button_post_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:width="50dp"
android:background="#color/AccentColor"
android:text="Post"
android:textColor="#ffffff"/>