app crashes when loading in android - android

unfortunately my app crashes when this activity is being loaded:
public class ManagerActivity extends Activity implements OnClickListener {
private TabHost th;
private EditText addpray1;
private EditText addplace1;
private EditText addtime1;
private Button addpray1Button;
private EditText removepray1;
private EditText removeplace1;
private EditText removetime1;
private Button removepray1Button;
private EditText addpray2;
private EditText addplace2;
private EditText addtime2;
private Button addpray2Button;
private EditText removepray2;
private EditText removeplace2;
private EditText removetime2;
private Button removepray2Button;
private EditText addtitlemessage;
private EditText addinfomessage;
private Button addmessagebutton;
private EditText removetitlemessage;
private Button removemessagebutton;
private EditText addtitleevent;
private EditText addinfoevent;
private Button addeventbutton;
private EditText removetitleevent;
private Button removeeventbutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.manager);
th = (TabHost) findViewById(R.id.tabhost);
InitTabs(th);
InitFields();
addpray1Button.setOnClickListener(this);
removepray1Button.setOnClickListener(this);
addpray2Button.setOnClickListener(this);
removepray2Button.setOnClickListener(this);
addeventbutton.setOnClickListener(this);
removeeventbutton.setOnClickListener(this);
addmessagebutton.setOnClickListener(this);
removeeventbutton.setOnClickListener(this);
}
private void InitTabs(TabHost th){
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("עדכון הודעות");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("עדכון אירועים");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("עדכון זמני השבת");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab4);
specs.setIndicator("עדכון זמני יום חול");
th.addTab(specs);
}
private void InitFields() {
// TODO Auto-generated method stub
addpray1 = (EditText) findViewById(R.id.addPray1);
addplace1 = (EditText) findViewById(R.id.place1);
addtime1 = (EditText) findViewById(R.id.time1);
addpray1Button = (Button) findViewById(R.id.addPrayButton1);
removepray1 = (EditText) findViewById(R.id.removePray1);
removeplace1 = (EditText) findViewById(R.id.time_remove1);
removetime1 = (EditText) findViewById(R.id.place_remove1);
removepray1Button = (Button) findViewById(R.id.removePrayButton1);
addpray2 = (EditText) findViewById(R.id.pray2);
addplace2 = (EditText) findViewById(R.id.place2);
addtime2 = (EditText) findViewById(R.id.time2);
addpray2Button = (Button) findViewById(R.id.addPrayButton2);
removepray2 = (EditText) findViewById(R.id.removePray2);
removeplace2 = (EditText) findViewById(R.id.place_remove2);
removetime2 = (EditText) findViewById(R.id.time_remove2);
removepray2Button = (Button) findViewById(R.id.removePrayButton2);
addtitlemessage = (EditText) findViewById(R.id.titleMessage);
addinfomessage = (EditText) findViewById(R.id.messageInfo);
addmessagebutton = (Button) findViewById(R.id.addMessageButton);
removetitlemessage = (EditText) findViewById(R.id.removeMessage);
removemessagebutton = (Button) findViewById(R.id.removeMessageButton);
addtitleevent = (EditText) findViewById(R.id.addEvent);
addinfoevent = (EditText) findViewById(R.id.eventInfo);
addeventbutton = (Button) findViewById(R.id.addEventButton);
removetitleevent = (EditText) findViewById(R.id.removeEvent);
removeeventbutton = (Button) findViewById(R.id.removeEventButton);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
and the xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressbar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת הודעה"
android:textSize="25sp" />
<EditText
android:id="#+id/titleMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addMessage"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<EditText
android:id="#+id/messageInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titleMessage"
android:hint="מידע"
android:lines="4"
android:scrollHorizontally="true" />
<Button
android:id="#+id/addMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/messageInfo"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removeMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת הודעה"
android:textSize="25sp" />
<EditText
android:id="#+id/titleMessage_remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removeMessage"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<Button
android:id="#+id/removeMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/titleMessage_remove"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת אירוע"
android:textSize="25sp" />
<EditText
android:id="#+id/titleEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addEvent"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<EditText
android:id="#+id/eventInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titleEvent"
android:hint="מידע"
android:lines="4"
android:scrollHorizontally="true" />
<Button
android:id="#+id/addEventButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/eventInfo"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removeEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת אירוע"
android:textSize="25sp" />
<EditText
android:id="#+id/titleEvent_remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removeEvent"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<Button
android:id="#+id/removeEventButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/titleEvent_remove"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addPray1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addPray1"
android:hint="תפילה" />
<EditText
android:id="#+id/place1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray1"
android:hint="מקום" />
<EditText
android:id="#+id/time1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place1"
android:hint="שעה" />
<Button
android:id="#+id/addPrayButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time1"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removePray1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray_remove1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removePray1"
android:hint="תפילה" />
<EditText
android:id="#+id/place_remove1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray_remove1"
android:hint="מקום" />
<EditText
android:id="#+id/time_remove1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place_remove1"
android:hint="שעה" />
<Button
android:id="#+id/removePrayButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time_remove1"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addPray2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addPray2"
android:hint="תפילה" />
<EditText
android:id="#+id/place2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray2"
android:hint="מקום" />
<EditText
android:id="#+id/time2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place2"
android:hint="שעה" />
<Button
android:id="#+id/addPrayButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time2"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removePray2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray_remove2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removePray2"
android:hint="תפילה" />
<EditText
android:id="#+id/place_remove2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray_remove2"
android:hint="מקום" />
<EditText
android:id="#+id/time_remove2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place_remove2"
android:hint="שעה" />
<Button
android:id="#+id/removePrayButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time_remove2"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
i guess it's because i'm loading a lot of views...
I'm also wanna to add a progress bar that works while the layout is loading until its done.
how can i fix that?
thanks :)

Related

How to click button inside listview

I know this problem already asked many times but i still can't get effective way for solving this. I try for use ListView with clickable/editable widget and Android : How to set onClick event for Button in List item of ListView as reference but the result is i need click button several time for executing my program. Here my program
LeadActivity.xml
<?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:orientation="vertical"
tools:context=".LeadSalesActivity">
<LinearLayout
android:background="#E9ECEB"
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/b_menusamping2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:background="#drawable/menu_button"
android:backgroundTint="#27D01B"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome,"
android:textSize="20sp"
android:textStyle="italic"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/t_username3"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Rizaldi"
android:textColor="#android:color/black"
android:textSize="25sp"
android:textStyle="bold"
android:fontFamily="#font/action_man_bold"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_refresh2"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white">
<ImageView
android:backgroundTint="#27D01B"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:background="#drawable/icon_update"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="("
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:textStyle="bold"
android:id="#+id/count_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=")"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<Button
android:id="#+id/btn_add"
android:layout_marginRight="20dp"
android:backgroundTint="#android:color/holo_blue_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tambah Lead"
android:textAllCaps="false"/>
</LinearLayout>
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<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:text="Tanggal"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:layout_marginLeft="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telp"
android:textColor="#android:color/black"
android:textSize="20sp"/>
</LinearLayout>
<ListView
android:id="#+id/listviewlead"
tools:listitem="#layout/c_lead"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/back6"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"/>
</LinearLayout>
c_lead.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_tgl"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Tgl"
android:textSize="15sp"
android:textStyle="italic"
android:textColor="#000000" />
<TextView
android:id="#+id/t_lead4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Lead"
android:textSize="15sp"
android:textColor="#000000" />
<TextView
android:id="#+id/t_numberphone"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="right"
android:text="No.Telp"
android:textSize="15sp"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/pencil_icon"/>
</LinearLayout>
<LinearLayout
android:id="#+id/btn_delete"
android:layout_marginLeft="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/delete_icon"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_alamat"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Alamat"
android:textColor="#android:color/black"
android:textSize="15sp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
MyAdapter
public View getView(final int _position, View _v, ViewGroup _container) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _view = _v;
if (_view == null) {
_view = _inflater.inflate(R.layout.c_lead, null);
}
final HashMap<String, Object> hashMap = _data.get(_position);
final TextView t_tanggal = (TextView) _view.findViewById(R.id.t_tgl);
final TextView t_lead = (TextView) _view.findViewById(R.id.t_lead4);
final TextView t_alamat = (TextView) _view.findViewById(R.id.t_alamat);
final TextView t_numberphone = (TextView) _view.findViewById(R.id.t_numberphone);
final LinearLayout btn_edit = (LinearLayout) _view.findViewById(R.id.btn_edit);
final LinearLayout btn_delete = (LinearLayout) _view.findViewById(R.id.btn_delete);
String dateString = _data.get(_position).get("create_date").toString().replace("-","");
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmm");
format1.setTimeZone(TimeZone.getTimeZone("GMT+7"));
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
try {
Date date = format1.parse(dateString);
String dateFinal = format2.format(date);
t_tanggal.setText(String.valueOf((long)(_position + 1)).concat(".").concat(dateFinal));
} catch (ParseException e) {
e.printStackTrace();
}
t_lead.setText(_data.get((int)_position).get("type").toString());
t_alamat.setText(_data.get((int)_position).get("street").toString());
if (_data.get((int)_position).get("mobile").toString().equals(true)){
t_numberphone.setText("Tanpa Nomor");
} else {
t_numberphone.setText(_data.get((int)_position).get("phone").toString());
}
btn_edit.setFocusable(false);
btn_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i.setClass(getApplicationContext(), AddLeadSalesActivity.class);
startActivity(i);
}
});
btn_delete.setFocusable(false);
btn_delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Data Tidak Bisa Dihapus", Toast.LENGTH_SHORT).show();
}
});
return _view;
}
Is there any mistake inside my program? How to solve this?

android implement dropdown with SearchView in activity

In activity I use SearchView and I want to implement dropdown when any result occurred is it possible ?? thanks in adavance.
searchActivity.java code
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_activity);
isSearchVisible = false;
isHomeVisible = true;
mActivity = this;
mContext = getApplicationContext();
mSearchView = (SearchView) findViewById(R.id.m_searchview);
edtFromDate = (EditText) findViewById(R.id.edt_from_date);
edtEndDate = (EditText) findViewById(R.id.edt_end_date);
btnSearchNow = (Button) findViewById(R.id.btn_search_now);
int searchPlateId = mSearchView.getContext().getResources()
.getIdentifier("android:id/search_plate", null, null);
View searchPlateView = mSearchView.findViewById(searchPlateId);
if (searchPlateView != null) {
searchPlateView.setBackgroundColor(Color.WHITE);
}
}
search_activity.xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#color/main_background"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="#dimen/activity_horizontal_margin">
<SearchView android:id="#+id/m_searchview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:closeIcon="#drawable/close"
android:searchIcon="#drawable/search_blue"
android:padding="2dp"
android:background="#drawable/editext_background"
android:layout_marginBottom="#dimen/activity_horizontal_margin"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_from_date"
android:textSize="20sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="15dp"/>
<EditText android:id="#+id/edt_from_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:drawableRight="#drawable/calendar"
android:paddingRight="20dp"
android:enabled="false"
style="#style/loginEditTextView"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_end_date"
android:textSize="20sp"
android:textColor="#color/colorAccent"
android:layout_marginBottom="15dp"/>
<EditText android:id="#+id/edt_end_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:drawableRight="#drawable/calendar"
android:paddingRight="20dp"
android:enabled="false"
style="#style/loginEditTextView"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/btn_search_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/search_now"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
here's manifest code for manifest app
<activity android:name=".activity.SearchActivity"
android:label="#string/title_search_activity"
android:configChanges="orientation"></activity>

LinearLayout is null inside button's onClick

I'm trying to hide a linearlayout on a button click and display another linearlayout which is in the same layout file. But the linearlayouts are null inside the onclick of the button.
The displayLayout and editLayout are null.
displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
displayLayout.setVisibility(View.GONE); //error occurs here
editLayout.setVisibility(View.VISIBLE);
}
});
}
Here's the layout file:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.prematixsofs.taxiapp.EditUserDetails">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<!--Display UserDetails Layout-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/displayLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<TextView
android:id="#+id/phNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<TextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:inputType="textEmailAddress"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp">
<Button
android:id="#+id/edit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/button_custom"
android:text="Edit"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<!--Edit Layout -->
<LinearLayout
android:id="#+id/editLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="#+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="#+id/editPhNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="#+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
<EditText
android:id="#+id/editConfirmPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/custom_edittext"
android:gravity="center"
android:padding="8dp"
android:paddingLeft="10dp"
android:paddingRight="5dp" />
</LinearLayout>
Just fix your view ID in your code
displayLayout = (LinearLayout) findViewById(R.id.displayLayout);
editLayout = (LinearLayout) findViewById(R.id.editLayout);
edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
displayLayout.setVisibility(View.GONE);
editLayout.setVisibility(View.VISIBLE);
}
});
}
error code displayLayout = (LinearLayout) findViewById(R.id.linearLayout);
right code displayLayout = (LinearLayout) findViewById(R.id.displayLayout);
you set a not exist id.

How to change a lot of textview to scrolled list layout

I'm begginer in programming and i need your help. I have to write application which will be display sensor results as text, and i did it in wrong way (code is working, but when screen is not scrolling).
Below i copy XML file:
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/rLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rPressure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rLight"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rHumidity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rPressure"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rProximity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rHumidity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rProximity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rAccel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rTemp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rGyro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rAccel"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rMag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rGyro"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rRotation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rMag"/>
<TextView
android:id="#+id/rGravity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rRotation"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rSCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rGravity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rSDetector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rSCounter"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rLinearAcc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rSDetector"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rSignMotion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rLinearAcc"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rNoise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rSignMotion"
android:textAppearance="?android:attr/textAppearanceMedium" />
and this is main class:
public class MainActivity extends Activity implements EventListener, StepCounterListener, LinearAccListener, StepDetectorListener, LightSensorListener, PressureSensorListener, GravitySensorListener, RotationVectorListener, RelativeHumidityListener, ProximitySensorListener, TempSensorListener, AccelerometerSensorListener, GyroSensorListener, MagSensorListener {
private TextView lightText, pressureText, signText, noiseText, humidityText, linearAccText, proximityText, tempText, accelText, gyroText, magText, rotationText, gravityText, stepDetectorText, stepCounterText;
private LightSensor mLightSensor;
private PressureSensor mPressureSensor;
private RelativeHumiditySensor mRelativeHumidity;
private ProximitySensor mProximitySensor;
private TemperatureSensor mTempSensor;
private AccelerometerSensor mAccelSensor;
private GyroscopeSensor mGyroSensor;
private MagnetometerSensor mMagSensor;
private RotationSensor mRotSensor;
private GravitySensor mGravitySensor;
private StepCounterSensor mStepCounter;
private StepDetectorSensor mStepDetector;
private LinearAccelerometer mLinearAcc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lightText = (TextView)findViewById(R.id.rLight);
pressureText = (TextView)findViewById(R.id.rPressure);
humidityText = (TextView)findViewById(R.id.rHumidity);
proximityText = (TextView)findViewById(R.id.rProximity);
tempText = (TextView)findViewById(R.id.rTemp);
accelText = (TextView)findViewById(R.id.rAccel);
gyroText = (TextView)findViewById(R.id.rGyro);
magText = (TextView)findViewById(R.id.rMag);
rotationText = (TextView)findViewById(R.id.rRotation);
gravityText = (TextView)findViewById(R.id.rGravity);
stepCounterText = (TextView)findViewById(R.id.rSCounter);
stepDetectorText = (TextView)findViewById(R.id.rSDetector);
linearAccText = (TextView)findViewById(R.id.rLinearAcc);
signText = (TextView)findViewById(R.id.rSignMotion);
noiseText = (TextView)findViewById(R.id.rNoise);
mLightSensor = new LightSensor(getBaseContext());
mLightSensor.setListener(this);
mPressureSensor = new PressureSensor(getBaseContext());
mPressureSensor.setListener(this);
mRelativeHumidity = new RelativeHumiditySensor(getBaseContext());
mRelativeHumidity.setListener(this);
mProximitySensor = new ProximitySensor(getBaseContext());
mProximitySensor.setListener(this);
mTempSensor = new TemperatureSensor(getBaseContext());
mTempSensor.setListener((TempSensorListener) this);
[...]
}
public void onLightSensorChanged(String lux){
lightText.setText("LIGHT level: " + lux);
}
public void onPressureSensorChanged(String pressure){
//items.add("PRESSURE: " + pressure);
pressureText.setText("PRESSURE: " + pressure);
}
[...]
I tried use ArrayString, listAdapter but i had always a lot of errors.. please help
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/rLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/rPressure"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
.....................
</LinearLayout>
</ScrollView>
you need to use a scrollview , just insert your XML contents inside this before the and it should work:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ScrollView>
</LinearLayout>

Android setText ar the Master Page of the Tab

I have got the following code to set the values of the EditText at the header bar (master flow) but it failes and no values are assigned.
Would you please tell me how setText ?
The below is my code
(My Master Activity)
#SuppressWarnings("deprecation")
public class MainActivity extends Activity
{
private AsyncTask <Void , Void, Void> mRegisterTask ;
private String userid;
private String orderid;
...
View inflatedView = getLayoutInflater().inflate(R.layout.activity_main, null);
final EditText s = (EditText) inflatedView.findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
activity_main
<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:layout_margin="0dp"
android:background="#drawable/bg_with_header"
android:padding="0dp"
tools:context=".MainActivity" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:padding="0dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:orientation="vertical"
android:padding="0dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="82dp"
android:layout_margin="0dp"
android:layout_marginRight="50dp"
android:orientation="horizontal"
android:padding="0dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:src="#drawable/header_tv1231231231231bnvlogo" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="82dp"
android:layout_gravity="center"
android:layout_toLeftOf="#+id/headerLogin"
android:scrollbars="none" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="300dp"
android:layout_height="86dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:showDividers="none"
android:tabStripEnabled="false" />
</HorizontalScrollView>
<RelativeLayout
android:id="#+id/headerLogin"
android:layout_width="wrap_content"
android:layout_height="82dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/txtbg"
android:ems="10"
android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding=" 5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#BDBDBD" />
<EditText
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/textView1"
android:background="#drawable/txtbg"
android:ems="10"
android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#BDBDBD" />
<TextView
android:id="#+id/textVieasas2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textVieasas"
android:layout_alignBottom="#+id/textVieasas"
android:layout_toRightOf="#+id/textView2"
android:text="Last Login Date"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textVieasas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/textView2"
android:text="Sales Code"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:padding="0dp" />
</LinearLayout>
</TabHost>
you can also simple use this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText s = (EditText) findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
}
Do this way
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText s = (EditText) findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
// or
View inflatedView = getLayoutInflater().inflate(R.layout.activity_main, null);
final EditText s = (EditText) inflatedView.findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
setContentView(inflatedView);
}

Categories

Resources