Update and remove item in ListView - java

when make edit to array list by popup windows or remove item by long click
it just update and remove last value
arraylist and adapter and listview not updated together
this is my code:
CustomListViewAapter.java
package com.zoom.plumbingcalculation;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
public class CustomListViewAdapter extends BaseAdapter{
public static final String colFrom="From";
public static final String colTo="To";
public static final String colCFM="CFM";
public static final String colDia="Dia";
public static final String colLength="Length";
public static final String colTotLoss="Loss";
public static final String colDP="DP";
public ArrayList<HashMap<String, String>> list;
Activity activity;
TextView txtFrom;
TextView txtTo;
TextView txtCFM;
TextView txtDia;
TextView txtLength;
TextView txtTotLoss;
TextView txtDP;
public CustomListViewAdapter(Activity activity, ArrayList<HashMap<String, String>> list){
super();
this.activity=activity;
this.list=list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=activity.getLayoutInflater();
if(convertView == null){
convertView=inflater.inflate(R.layout.custom_list_view, null);
txtFrom=(TextView) convertView.findViewById(R.id.From);
txtTo=(TextView) convertView.findViewById(R.id.To);
txtCFM=(TextView) convertView.findViewById(R.id.CFM);
txtDia=(TextView) convertView.findViewById(R.id.Dia);
txtLength=(TextView) convertView.findViewById(R.id.Length);
txtTotLoss=(TextView) convertView.findViewById(R.id.TotLoss);
txtDP=(TextView) convertView.findViewById(R.id.DP);
}
HashMap<String, String> map=list.get(position);
txtFrom.setText(map.get(colFrom));
txtTo.setText(map.get(colTo));
txtCFM.setText(map.get(colCFM));
txtDia.setText(map.get(colDia));
txtLength.setText(map.get(colLength));
txtTotLoss.setText(map.get(colTotLoss));
txtDP.setText(map.get(colDP));
return convertView;
}
}
Activity.java
package com.zoom.plumbingcalculation;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colCFM;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colDP;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colDia;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colFrom;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colLength;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colTo;
import static com.zoom.plumbingcalculation.CustomListViewAdapter.colTotLoss;
public class ps_ss_compressed_air extends Activity {
//Compressed Air Variable
private ImageButton CAButAdd;
private ListView CALvDataTable;
private ArrayList<HashMap<String, String>> CALvDataTableListItems;
private CustomListViewAdapter CALvDataTableAdapter;
//Compressed Air Popup Add Variable
private LayoutInflater layoutAddInflater;
private View popupAddView;
private PopupWindow popupAddWindow;
private Button CAPAButAdd;
private Button CAPAButCancel;
private Spinner CAPASpDia;
private EditText CAPATxtFrom;
private EditText CAPATxtTo;
private EditText CAPATxtCFM;
private EditText CAPATxtLength;
//Compressed Air Popup Edit Variable
private LayoutInflater layoutEditInflater;
private View popupEditView;
private PopupWindow popupEditWindow;
private Button CAPEButEdit;
private Button CAPEButCancel;
private Spinner CAPESpDia;
private EditText CAPETxtFrom;
private EditText CAPETxtTo;
private EditText CAPETxtCFM;
private EditText CAPETxtLength;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ps_ss_compressed_air);
//Compressed Air Variable
CAButAdd = (ImageButton) findViewById(R.id.CAButAdd);
CALvDataTable =(ListView) findViewById(R.id.CALvDataTable);
CALvDataTableListItems= new ArrayList<HashMap<String,String>>();
CALvDataTableAdapter=new CustomListViewAdapter(this, CALvDataTableListItems);
CALvDataTable.setAdapter(CALvDataTableAdapter);
CAButAdd.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
layoutAddInflater = (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
popupAddView = layoutAddInflater.inflate(R.layout.ps_ss_compressed_air_popup_add, null);
//popupView.setAlpha(0.5F);
popupAddView.setAlpha(1);
popupAddWindow = new PopupWindow(
popupAddView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
CAPAButAdd = (Button)popupAddView.findViewById(R.id.CAPAButAdd);
CAPAButCancel = (Button)popupAddView.findViewById(R.id.CAPAButCancel);
CAPASpDia = (Spinner) popupAddView.findViewById(R.id.CAPASpDia);
CAPATxtFrom = (EditText) popupAddView.findViewById(R.id.CAPATxtFrom);
CAPATxtTo = (EditText) popupAddView.findViewById(R.id.CAPATxtTo);
CAPATxtCFM = (EditText) popupAddView.findViewById(R.id.CAPATxtCFM);
CAPATxtLength = (EditText) popupAddView.findViewById(R.id.CAPATxtLength);
CAPAButAdd.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
//Add--------------------------------------------------------------------------------------------
HashMap<String,String> temp = new HashMap<>();
temp.put(colFrom, CAPATxtFrom.getText().toString());
temp.put(colTo, CAPATxtTo.getText().toString());
temp.put(colCFM, CAPATxtCFM.getText().toString());
temp.put(colDia, CAPASpDia.getSelectedItem().toString());
temp.put(colLength, CAPATxtLength.getText().toString());
temp.put(colTotLoss, "");
temp.put(colDP, "");
CALvDataTableListItems.add(temp);
CALvDataTableAdapter.notifyDataSetChanged();
//-----------------------------------------------------------------------------------------------
popupAddWindow.dismiss();
}});
CAPAButCancel.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupAddWindow.dismiss();
}});
//popupWindow.showAsDropDown(CAButAdd, 50, 50);
popupAddWindow.showAtLocation(popupAddView, Gravity.CENTER,0,0);
popupAddWindow.setFocusable(true);
popupAddWindow.update();
}});
CALvDataTable.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id)
{
layoutEditInflater = (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
popupEditView = layoutEditInflater.inflate(R.layout.ps_ss_compressed_air_popup_edit, null);
popupEditView.setAlpha(1);
popupEditWindow = new PopupWindow(
popupEditView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
CAPEButEdit = (Button)popupEditView.findViewById(R.id.CAPEButEdit);
CAPEButCancel = (Button)popupEditView.findViewById(R.id.CAPEButCancel);
CAPESpDia = (Spinner) popupEditView.findViewById(R.id.CAPESpDia);
CAPETxtFrom = (EditText) popupEditView.findViewById(R.id.CAPETxtFrom);
CAPETxtTo = (EditText) popupEditView.findViewById(R.id.CAPETxtTo);
CAPETxtCFM = (EditText) popupEditView.findViewById(R.id.CAPETxtCFM);
CAPETxtLength = (EditText) popupEditView.findViewById(R.id.CAPETxtLength);
HashMap<String, String> temp=CALvDataTableListItems.get(position);
CAPETxtFrom.setText(temp.get(colFrom));
CAPETxtTo.setText(temp.get(colTo));
CAPETxtCFM.setText(temp.get(colCFM));
CAPESpDia.setSelection(((ArrayAdapter<String>)CAPESpDia.getAdapter()).getPosition(temp.get(colDia)));
CAPETxtLength.setText(temp.get(colLength));
CAPEButEdit.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
//Edit-------------------------------------------------------------------------------------------
HashMap<String,String> temp= CALvDataTableListItems.get(position);
temp.put(colFrom, CAPETxtFrom.getText().toString());
temp.put(colTo, CAPETxtTo.getText().toString());
temp.put(colCFM, CAPETxtCFM.getText().toString());
temp.put(colDia, CAPESpDia.getSelectedItem().toString());
temp.put(colLength, CAPETxtLength.getText().toString());
temp.put(colTotLoss, "");
temp.put(colDP, "");
CALvDataTableListItems.set(position,temp);
CALvDataTableAdapter.notifyDataSetChanged();
//-----------------------------------------------------------------------------------------------
popupEditWindow.dismiss();
}});
CAPEButCancel.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupEditWindow.dismiss();
}});
//popupWindow.showAsDropDown(CAButEdit, 50, 50);
popupEditWindow.showAtLocation(popupEditView, Gravity.CENTER,0,0);
popupEditWindow.setFocusable(true);
popupEditWindow.update();
//Toast.makeText(ps_ss_compressed_air.this, Integer.toString(position+1) + " Clicked", Toast.LENGTH_SHORT).show();
}
});
CALvDataTable.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
{
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
CALvDataTableListItems.remove(position);
CALvDataTableAdapter.notifyDataSetChanged();
Toast.makeText(ps_ss_compressed_air.this,"Removed", Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
custom_list_view.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="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:divider="#000000"
android:weightSum="7">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/From"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/To"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/CFM"
android:layout_weight="1" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/Dia"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/Length"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/TotLoss"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:id="#+id/DP"
android:layout_weight="1"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
</LinearLayout>
Activity.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:id="#+id/CAappbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/CAtoolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:logo="#mipmap/ic_launcher"
app:title="#string/app_name">
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingStart="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="14sp"
android:text="#string/Compressed_Air_Name"
android:id="#+id/CALabCAName"
android:layout_weight="7"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/CAButAdd"
android:layout_weight="1"
android:background="#drawable/ps_ss_compressed_air_but_add"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/CAappbar"
android:id="#+id/linearLayoutCAHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:divider="#000000">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/Nodes_Lab"
android:id="#+id/CALabNodes"
android:textStyle="bold"
android:layout_weight="1"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:weightSum="2"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/Nodes_From_Lab"
android:id="#+id/CALabFrom"
android:textStyle="bold"
android:layout_weight="1"/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/Nodes_To_Lab"
android:id="#+id/CALabTo"
android:textStyle="bold"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/CFM_Lab"
android:id="#+id/CALabCFM"
android:textStyle="bold"
android:layout_weight="1"/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/Diameter_Lab"
android:id="#+id/CALabDia"
android:textStyle="bold"
android:layout_weight="1"/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/Length_Lab"
android:id="#+id/CALabLength"
android:textStyle="bold"
android:layout_weight="1"/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/Total_Loss_Lab"
android:gravity="center"
android:id="#+id/CALabTotLoss"
android:textStyle="bold"
android:layout_weight="1"/>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#000000" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/Pressure_Drop_Lab"
android:id="#+id/CALabDP"
android:textStyle="bold"
android:layout_weight="1"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/linearLayoutCAHeader"
android:id="#+id/CALvDataTable"
android:longClickable="true"/>
</RelativeLayout>

Related

EditText autoscroll doesn't work after showing dialog

I'm developing an app for users to share their books. To achieve this, I'm getting different data about the book from the user. The problem is, horizontal autoscrolling of all EditTexts are working until Dialog has been shown and dismissed. Once a dialog has been dismissed on the fragment, horizontal autoscrolling of the EditText's on this layout won't work.
I added:
android:focusable="true"
android:focusableInTouchMode="true"
to parent layout of the edittext but doesn't work.
Also to make sure that autoscrolling is enabled I've added:
android:scrollHorizontally="true"
But none of above helped.
Here is XML code of the fragment layout.
<?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="match_parent"
android:background="#color/white"
android:orientation="vertical"
android:paddingStart="#dimen/dp25"
android:paddingEnd="#dimen/dp25"
tools:context=".UI.Fragments.SharePostFragments.Fragment1.OverViewFragment">
<LinearLayout
android:id="#+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<EditText
android:id="#+id/edit_text_name_of_book"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:fontFamily="#font/segoe_ui_semi_bold"
android:hint="#string/name_of_book"
android:inputType="text"
android:maxLength="50"
android:maxLines="1"
android:scrollHorizontally="true"
android:textAlignment="textStart"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="#dimen/font22" />
<TextView
android:id="#+id/text_view_number_of_characters"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="#dimen/dp10"
android:fontFamily="#font/segoe_ui_light"
android:text="#string/_0_50"
android:textColor="#color/colorAccent"
android:textSize="#dimen/font16"
tools:ignore="RtlSymmetry" />
<EditText
android:id="#+id/edit_text_name_of_author"
android:layout_width="match_parent"
android:layout_height="#dimen/textBoxHeight"
android:layout_marginTop="#dimen/dp30"
android:background="#drawable/round_text_box_gray"
android:fontFamily="#font/segoe_ui_regular"
android:hint="#string/name_of_writer"
android:inputType="text"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textColor="#color/colorPrimaryDark"
android:textColorHint="#color/colorPrimaryDark"
android:textSize="#dimen/font16" />
<RelativeLayout
android:id="#+id/constraint_layout_1"
android:layout_width="match_parent"
android:layout_height="#dimen/textBoxHeight"
android:layout_marginTop="#dimen/dp20"
android:background="#drawable/round_text_box_border_gray"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:fontFamily="#font/segoe_ui_regular"
android:paddingStart="#dimen/dp20"
android:paddingEnd="#dimen/dp20"
android:text="#string/price_of_book"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/font16" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:paddingStart="#dimen/dp20"
android:paddingEnd="#dimen/dp20"
android:text="#string/azn_sign"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/font16" />
<EditText
android:id="#+id/edit_text_price_of_book"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="#+id/textView2"
android:background="#color/white"
android:clickable="false"
android:hint="#string/_0_0"
android:inputType="text|numberDecimal"
android:maxLength="6"
android:singleLine="true"
android:textColorHint="#android:color/black" />
</RelativeLayout>
<LinearLayout
android:id="#+id/constraint_layout_conditions_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp20"
android:background="#drawable/round_text_box_border_gray"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linear_layout_1"
android:layout_width="match_parent"
android:layout_height="#dimen/textBoxHeight"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:gravity="center_vertical"
android:paddingStart="#dimen/dp20"
android:paddingEnd="#dimen/dp20"
android:text="#string/book_condition_placeholder"
android:textColor="#color/colorPrimaryDark" />
<ImageButton
android:id="#+id/image_button_conditions"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="#dimen/dp10"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_spinner" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_conditions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="#+id/text_view_new"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="#dimen/dp20"
android:paddingTop="#dimen/dp10"
android:paddingEnd="#dimen/dp20"
android:paddingBottom="#dimen/dp10"
android:text="#string/_new"
android:textColor="#color/dark_gray_text_color" />
<TextView
android:id="#+id/text_view_normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="#dimen/dp20"
android:paddingTop="#dimen/dp10"
android:paddingEnd="#dimen/dp20"
android:paddingBottom="#dimen/dp10"
android:text="#string/normal"
android:textColor="#color/dark_gray_text_color" />
<TextView
android:id="#+id/text_view_old"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="#dimen/dp20"
android:paddingTop="#dimen/dp10"
android:paddingEnd="#dimen/dp20"
android:paddingBottom="#dimen/dp10"
android:text="#string/old"
android:textColor="#color/dark_gray_text_color" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/constraint_layout_languages_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp20"
android:background="#drawable/round_text_box_border_gray"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linear_layout_2"
android:layout_width="match_parent"
android:layout_height="#dimen/textBoxHeight"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:gravity="center_vertical"
android:paddingStart="#dimen/dp20"
android:paddingEnd="#dimen/dp20"
android:text="#string/language"
android:textColor="#color/colorPrimaryDark" />
<ImageButton
android:id="#+id/image_button_languages"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="#dimen/dp10"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="#drawable/ic_spinner" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_languages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="#dimen/dp20"
android:paddingEnd="#dimen/dp20"
android:paddingBottom="#dimen/dp10"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Fragment Java code:
package org.kitapp.UI.Fragments.SharePostFragments.Fragment1;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import org.kitapp.R;
import org.kitapp.UI.Dialogs.ConditionDialog.ConditionOfBookDialog;
import org.kitapp.UI.Dialogs.LanguageDialog.LanguageDialog;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTextChanged;
public class OverViewFragment extends Fragment implements OverViewContractor.View {
private final String TAG = OverViewFragment.class.getSimpleName();
private Context mContext;
private OverViewCallback mListener;
private OverViewPresenter mPresenter;
#BindView(R.id.constraint_layout_conditions_root)
LinearLayout conditionRoot;
#BindView(R.id.constraint_layout_languages_root)
LinearLayout languagesRoot;
#BindView(R.id.linear_layout_conditions)
LinearLayout conditions;
#BindView(R.id.root_layout)
LinearLayout rootLayout;
#BindView(R.id.text_view_number_of_characters)
TextView numberOfChars;
#BindView(R.id.edit_text_name_of_book)
EditText nameOfBook;
public interface OverViewCallback {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_over_view, container, false);
ButterKnife.bind(this, view);
new OverViewPresenter(this);
//rootLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
return view;
}
////// CONTRACTOR METHODS //////
#Override
public void setPresenter(OverViewPresenter presenter) {
this.mPresenter = presenter;
}
////// LISTENERS //////
#Override
#OnClick(R.id.image_button_conditions)
public void showConds() {
ConditionOfBookDialog conditionOfBookDialog = new ConditionOfBookDialog(mContext);
conditionOfBookDialog.show();
}
#Override
#OnClick(R.id.image_button_languages)
public void showLangs() {
LanguageDialog languageDialog = new LanguageDialog(mContext);
languageDialog.show();
}
#Override
#SuppressLint("SetTextI18n")
#OnTextChanged(R.id.edit_text_name_of_book)
public void onNameOfBookChange() {
int len = nameOfBook.getText().toString().trim().length();
numberOfChars.setText(len + "/50");
if (len > 50) {
nameOfBook.setText(nameOfBook.getText().toString().substring(0, 50));
nameOfBook.setSelection(nameOfBook.getText().length());
}
}
////// FRAGMENT METHODS //////
#Override
public void onAttach(Context context) {
super.onAttach(context);
this.mContext = context;
if (context instanceof OverViewCallback) {
mListener = (OverViewCallback) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OverViewCallback");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
}
UI Design and Dialog
In the image above, there are EditTexts Name Of Book and Name of Author. Before showing a dialog, both of them work like a charm. When writing something, the cursor automatically scrolls to the end. Once Dialog has been shown and dismissed, none of them works properly, and the cursor stays at the end of the EditText but still the characters are being written continues in the hidden part.
In this UI it cannot be seen because of the issue, but I've written.
Roses are red, violets are blue, Stackoverflow I love u
But only Roses are red, violets are blue, Stac can be seen.
Weird buggy layout UI image
Please, help me to solve this problem. Thanks in advance.
As a solution, I don't know the underlying reason, but the problem solved once I removed Butterknife library from my project.

Animation Problems in Android

I've got few problems in using animation in android studios:
I'm trying to translate certain images at an angle. Like in the image below I want to move that attachment pin like icons to all the ends of the corner. How can I do this?
I was trying to scale up the image of the gear image in the center every time its tapped and scale down when tapped again. However, the image starts losing its quality. How can I prevent the quality from getting deteriorated?
Here's the code:
MainActivity.java
package com.rootonelabs.vicky.pulse;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import com.gigamole.library.PulseView;
public class MainActivity extends AppCompatActivity {
PulseView pulseView;
Button btnStart, btnStop;
ImageView gear;
ImageView icon1,icon2,icon3,icon4,icon5,icon6;
int chkClick = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pulseView = (PulseView)findViewById(R.id.pv);
btnStart = (Button)findViewById(R.id.btnStart);
btnStop = (Button)findViewById(R.id.btnStop);
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pulseView.startPulse();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pulseView.finishPulse();
}
});
gear = (ImageView)findViewById(R.id.gear);
gear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
gear.animate().scaleX(1.5f).scaleY(1.5f).setDuration(500);
animateDiagonalPan();
icon1 = findViewById(R.id.icon1);
icon1.animate().translationXBy(120).translationYBy(120).setDuration(500);
if(chkClick==0)
{
pulseView.animate().alpha(0).setDuration(500);
gear.animate().scaleX(1.5f).scaleY(1.5f).setDuration(500);
pulseView.finishPulse();
chkClick = 1;
}else{
pulseView.animate().alpha(1f).setDuration(500);
gear.animate().scaleX(1f).scaleY(1f).setDuration(500);
pulseView.startPulse();
chkClick = 0;
}
}
});
}
}
activity_main.xml
<?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-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f39c12"
tools:context="com.rootonelabs.vicky.pulse.MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnStart"
android:layout_weight="1"
android:text="START"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnStop"
android:layout_weight="1"
android:text="STOP"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:id="#+id/gear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/men3"/>
<ImageView
android:id="#+id/icon1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_video"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_archive"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_attachment_black_24dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_video"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_archive"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_attachment_black_24dp"/>
<com.gigamole.library.PulseView
android:id="#+id/pv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:pv_alpha="70"
app:pv_color="#FFF"
app:pv_icon="#drawable/men2"
app:pv_icon_width="100dp"
app:pv_icon_height="100dp"
app:pv_interpolator="#android:anim/linear_interpolator"
app:pv_measure="height"
app:pv_spawn_period="1000" />
</RelativeLayout>

Dynamically Remove EditText Field in LinearLayout

My problem is that once my editText fields are created, I don't know how to remove them one by one with the other button in my app. I don't really understand the android:id element as it relates to setID() in my java code. I guess my main question is, how do I figure out how to target dynamically created editText views with their id's if I don't know their id's. Here is my code, any help is really appreciated:
Java:
package com.zdowning.decisionmaker;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ScrollView;
import android.widget.Toast;
import java.lang.*;
import static com.zdowning.decisionmaker.R.layout.activity_main;
public class MainActivity extends AppCompatActivity {
public int numberOfLines = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getAnswer();
}
});
final Button add_button = (Button) findViewById(R.id.add_button);
add_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Add_Line();
}
});
final Button remove_button = (Button) findViewById(R.id.remove_button);
remove_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Remove_Line();
}
});
}
public void Add_Line() {
LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayoutDecisions);
// add edittext
EditText et = new EditText(this);
LinearLayout.LayoutParams p = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
et.setLayoutParams(p);
et.setId(numberOfLines++);
et.setText("Enter Answer #" + numberOfLines++);
ll.addView(et);
numberOfLines++;
Toast.makeText(MainActivity.this, "1", Toast.LENGTH_LONG).show();
}
public void Remove_Line() {
}
public void getAnswer() {
String[] options = new String[numberOfLines];
EditText text = (EditText)findViewById(R.id.editText2);
options[0] = text.getText().toString();
text = (EditText)findViewById(R.id.editText3);
options[1] = text.getText().toString();
text = (EditText)findViewById(R.id.editText4);
options[2] = text.getText().toString();
int number = (int)(Math.random() * 3);
String answer = options[number];
TextView answerBox = (TextView)findViewById(R.id.textView7);
answerBox.setText(answer);
}
}
XML:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d4cfcd">
tools:context="com.zdowning.decisionmaker.MainActivity">
<LinearLayout
android:id="#+id/linearLayoutMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center"
android:hint="Enter Your Question Here"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"/>
<LinearLayout
android:id="#+id/linearLayoutDecisions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center"
android:hint="Enter Answer #2" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center"
android:hint="Enter Answer #1" />
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="45dp"
android:gravity="center"
android:hint="Enter Answer #3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/add_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:text="+"
android:textColor="#android:color/background_light"
android:textSize="18sp"/>
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:id="#+id/remove_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:text="-"
android:textColor="#android:color/background_light"
android:textSize="18sp"
android:layout_margin="10dp"/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:text="DECIDE!"
android:textColor="#android:color/background_light"
android:textSize="18sp"
android:layout_centerInParent="true" />
</RelativeLayout>
<TextView
android:id="#+id/textView7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="20dp"
android:textColor="#android:color/black"
android:textSize="36sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
There is no relationship between android:id and your setID.
Check this answer to unsderstand more about that.
Anyway, one approach to achieve to remove a generated line could be based on the children index of your LinearLayout like this:
private LinearLayout mEditTextContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
mEditTextContainer = (LinearLayout)findViewById(R.id.linearLayoutDecisions);
...
}
public void addLine() {
// add edittext
EditText et = new EditText(this);
LinearLayout.LayoutParams p = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
et.setLayoutParams(p);
et.setText("Enter Answer #" + (mEditTextContainer.getChildCount()+1));
mEditTextContainer.addView(et);
Toast.makeText(MainActivity.this, "1", Toast.LENGTH_LONG).show();
}
public void removeLine() {
mEditTextContainer.removeViewAt(mEditTextContainer.getChildCount()-1);
}

App force closes when I click on a page

I designed a profile page of an android app. But, it force closes when I click to this page. How can I prevent crash?
Reference of my profile page
res/layout/fragment_profile_vp.xml
<FrameLayout 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"
tools:context="com.example.ray.myoufd.Profile_vp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/header_cover_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/profilebg" />
<ImageButton
android:id="#+id/user_profile_photo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_below="#+id/header_cover_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="-60dp"
android:elevation="5dp"
android:scaleType="centerCrop"
android:src="#drawable/defaultpropic" />
<RelativeLayout
android:id="#+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header_cover_image"
android:background="#color/grey"
android:elevation="4dp"
android:paddingBottom="24dp">
<TextView
android:id="#+id/user_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Name"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/user_profile_short_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_profile_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="profile short bio"
android:textColor="#fff"
android:textSize="14sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="0dp"
android:orientation="horizontal"
android:id="#+id/linearLayout1"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Name:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="43dp"
android:orientation="horizontal"
android:id="#+id/linearLayout2"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Gender:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="86dp"
android:orientation="horizontal"
android:id="#+id/linearLayout3"
android:background="#color/white" >
<TextView
android:layout_height="wrap_content"
android:text="Email:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="129dp"
android:orientation="horizontal"
android:id="#+id/linearLayout4"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Date o birth:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="172dp"
android:orientation="vertical"
android:id="#+id/linearLayout5"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Message to friend"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<Button
android:text="Logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_marginStart="115dp"
android:layout_marginLeft="115dp"
android:background="#color/green"
android:layout_marginTop="605dp" />
<Button
android:text="Save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:layout_marginTop="605dp"
android:layout_marginLeft="210dp"
android:layout_marginStart="210dp"
android:background="#color/green"
/>
</RelativeLayout>
</ScrollView>
</FrameLayout>
java/com.example.ray.myoufd/Profile_vp.java
package com.example.ray.myoufd;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Profile_vp extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile_vp, container, false);
}
}
java/com.example.ray.myoufd/MainPage.java
package com.example.ray.myoufd;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import com.gigamole.navigationtabbar.ntb.NavigationTabBar;
import java.util.ArrayList;
import java.util.List;
public class MainPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
initUI();
}
private void initUI() {
final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
final String[] colors = getResources().getStringArray(R.array.default_preview);
final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.home),
Color.parseColor(colors[0]))
.title("Home")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.search),
Color.parseColor(colors[1]))
.title("Search")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.friend),
Color.parseColor(colors[2])).
badgeTitle("123")
.title("Friend")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.personal),
Color.parseColor(colors[3]))
.title("Profile")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.chat),
Color.parseColor(colors[4]))
.title("Discuss")
.build()
);
navigationTabBar.setModels(models);
Search_vp search_Vp = new Search_vp();
Home_vp home_vp = new Home_vp();
Friend_vp friend_vp =new Friend_vp();
Discuss_vp discuss_vp = new Discuss_vp();
Profile_vp profile_vp = new Profile_vp();
List<Fragment> fragmentList = new ArrayList<>();
fragmentList.add(home_vp);
fragmentList.add(search_Vp);
fragmentList.add(friend_vp);
fragmentList.add(profile_vp);
fragmentList.add(discuss_vp);
FragmentPageAdapter fragmentPageAdapter =new FragmentPageAdapter(getSupportFragmentManager(),fragmentList);
viewPager.setAdapter(fragmentPageAdapter);
navigationTabBar.setViewPager(viewPager, 0);
navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
}
#Override
public void onPageSelected(final int position) {
navigationTabBar.getModels().get(position).hideBadge();
}
#Override
public void onPageScrollStateChanged(final int state) {
}
});
navigationTabBar.postDelayed(new Runnable() {
#Override
public void run() {
for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
navigationTabBar.postDelayed(new Runnable() {
#Override
public void run() {
model.showBadge();
}
}, i * 100);
}
}
}, 500);
}
}

CardView not displaying content due any errors

I created a Recyclerview in my main_activity and I wanted to use this cardview in a partial activity... I put extras variables and data to the new activity but any thing not showing in new activity...
this is my partial xml code (hotel_page.xml) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/card_view1"
android:layout_width="match_parent"
android:layout_height="288dp"
android:layout_margin="#dimen/card_margin"
android:elevation="3dp"
card_view:cardCornerRadius="0dp"
android:gravity="top">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/card"
android:focusable="true"
android:contextClickable="true"
android:gravity="top"
android:layout_alignParentBottom="true">
</RelativeLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="25dp"
android:paddingTop="10dp"
android:textColor="#color/cardview_dark_background"
android:textSize="15dp"
android:layout_above="#+id/count1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="#+id/thumbnail1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:scaleType="fitXY"
android:contextClickable="true"
android:layout_alignTop="#+id/title1" />
<TextView
android:id="#+id/count1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="25dp"
android:textSize="12dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
This is My HotelPageList.java :
package ir.homa;
public class HotelPageList {
private String name;
private int numOfRooms;
private int thumbnail;
public HotelPageList() {
}
public HotelPageList(String name, int numOfRooms, int thumbnail) {
this.name = name;
this.numOfRooms = numOfRooms;
this.thumbnail = thumbnail;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumOfRooms() {
return numOfRooms;
}
public void setNumOfRooms(int numOfRooms) {
this.numOfRooms = numOfRooms;
}
public int getThumbnail() {
return thumbnail;
}
public void setThumbnail(int thumbnail) {
this.thumbnail = thumbnail;
}
}
This is HotelPageAdapter.java :
package ir.homa;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.List;
/**
* Created by SMQ on 7/20/2016.
*/
public class HotelPageAdapter extends RecyclerView.Adapter<HotelPageAdapter.MyViewHolder> {
private Context mContext;
private List<HotelPageList> hotelPage;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title1, count1;
public ImageView thumbnail1, overflow1;
public MyViewHolder(View view) {
super(view);
title1 = (TextView) view.findViewById(R.id.title1);
count1 = (TextView) view.findViewById(R.id.count1);
thumbnail1 = (ImageView) view.findViewById(R.id.thumbnail1);
overflow1 = (ImageView) view.findViewById(R.id.overflow);
}
}
public HotelPageAdapter(Context mContext, List<HotelPageList> hotelPage) {
this.mContext = mContext;
this.hotelPage = hotelPage;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.hotel_page, parent, false);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
final HotelPageList hotel = hotelPage.get(position);
holder.title1.setText(hotel.getName());
holder.count1.setText(hotel.getNumOfRooms() + " اتاق");
// loading hotel cover using Glide library
Glide.with(mContext).load(hotel.getThumbnail()).into(holder.thumbnail1);
}
#Override
public int getItemCount() {return hotelPage.size();}
}
and this is result:
Where is problem ?
Try this way
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="288dp">
<android.support.v7.widget.CardView
android:id="#+id/card_view1"
android:layout_width="match_parent"
android:layout_height="288dp"
android:elevation="3dp"
card_view:cardCornerRadius="0dp"
android:gravity="top">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/card"
android:focusable="true"
android:contextClickable="true"
android:gravity="top"
android:layout_alignParentBottom="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:src="#drawable/ic_launcher"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<TextView
android:id="#+id/title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="25dp"
android:paddingTop="10dp"
android:textColor="#color/cardview_dark_background"
android:textSize="15dp"
android:text="Title"
android:layout_above="#+id/count1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="#+id/thumbnail1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:src="#drawable/ic_launcher"
android:contextClickable="true"
android:layout_alignTop="#+id/title1" />
<TextView
android:id="#+id/count1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="25dp"
android:textSize="12dp"
android:text="sub title"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>

Categories

Resources