I am a very Beginner to android development. I have a Main activity which contains a Button. Onclick of Button,it has to open a Simple Listview. Please Help me
//Main Layout - This is my Main activity Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#F0F2DF"
tools:context="com.pureconcept.HomePage" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/image001" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
android:text="UserName"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#DE2F32" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:ems="10" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#DE2F32" />
<EditText
android:id="#+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/textView1"
android:ems="10" />
<Button
android:id="#+id/Login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/EditText01"
android:layout_marginTop="14dp"
android:text="Sign in"
android:onClick="onclickSigin"/>
</RelativeLayout>
-----------------------------------
//Welcome Layout - This is my Welcome activity Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Menu_List"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0F2DF"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome Subbu!"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TwoLineListItem
android:id="#+id/twoLineListItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
// Homepage. Java. Here i am inflating the Two Layouts on the Click on button.
public void onclickSigin(View v)
{
// TODO Auto-generated method stub
LayoutInflater inflater = getLayoutInflater();
View appearance = inflater.inflate(R.layout.welcome_layout,(android.view.ViewGroup) findViewById(R.id.Menu_List));
}
}
// Welcome.java -- I am trying to Populate ListView . This should display on click of button from Homepage activity.
private void populateMenuList() {
// TODO Auto-generated method stub
String[] menuitems = getResources().getStringArray(R.array.menuitems);
ArrayAdapter<String> menuadapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menuitems);
ListView lv = (ListView) findViewById(R.id.Menu_List);
lv.setAdapter(menuadapter);
}
}
I get the following error :
Getting java.lang.RuntimeException: Unable to start activity ComponentInfo. I am very new to android. Please explain
Thanks
myButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ListView modeList = new ListView(this);
String[] stringArray = new String[] { "Bright Mode", "Normal Mode" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, stringArray);
modeList.setAdapter(modeAdapter);
modeList.setVisibility(View.VISISBLE);
}
});
Something like this should work for you.
just add following line below listview_object.setAdapter.array_adapter_object
array_adapter_objectname.notifyDataSetChange();
Related
Like it is said in the title I want to add 2 entries of two different EditText into 1 listrowitem of my ListView.
Now I just can add one entry.
onCreateView of my fragment
final ListView listView = (ListView) rootView.findViewById(R.id.listViewswipeview);
final EditText editText = (EditText) rootView.findViewById(R.id.editTextswipeView);
final EditText editText2 = (EditText) rootView.findViewById(R.id.editText2);
Button btnswipeview = (Button) rootView.findViewById(R.id.imagebuttonswipeview);
listItems = new ArrayList<String>();
listItems.add("First Item - added on Activity Create");
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, listItems);
listView.setAdapter(adapter);
btnswipeview.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View View) {
Toast toast = Toast.makeText(getActivity(),
"You clicked the button",
Toast.LENGTH_SHORT);
toast.show();
listItems.add(editText.getText().toString());
adapter.notifyDataSetChanged();
}
});
My fragment xml swipeview.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Titel"
android:textSize="15pt"
android:id="#+id/swipeviewtitle"
android:layout_gravity="center_horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipeViewimage"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#CFD8DC">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editTextswipeView"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imagebuttonswipeview"
android:src="#drawable/ic_menu_add"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editText2"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#CFD8DC">
<ListView
android:layout_margin="5dp"
android:id="#+id/listViewswipeview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:listitem="#layout/swipeviewrowitem"
android:clickable="true"
android:drawSelectorOnTop="true"
android:focusable="true"
android:choiceMode="singleChoice"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinnerswipeview"
android:entries="#array/day"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
my rowitem xml swipeviewrowitem.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:descendantFocusability="blocksDescendants"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/new.workout"
android:textColor="#000000"
android:id="#+id/mainText"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
So if I make a entry in each of the two EditText objects the first one should be added to android:id="#+id/mainText" and the second one to android:id="#+id/textView2" of the listrowitem.
How is it possible to do it?
Rather than using the stock ArrayAdapter with a built-in row layout:
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, listItems);
you'll probably want to create your own Adapter that extends ArrayAdapter, and pass it your custom row layout R.layout.swipeviewrowitem. You can add logic inside the custom Adapter to handle inputs to the EditTexts.
I have four tabs in my home screen and one of them takes user input,
I have a two problem one is when open tab activity then android keyboard automatically open
and another problem is keyboard coming after tabbar.
I already added android:windowSoftInputMode="adjustPan" in my menifetch file
I Share My code
My createchallan.xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="38dp"
android:text="Search" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/search"
android:layout_alignBottom="#+id/search"
android:layout_toRightOf="#+id/search"
android:background="#android:drawable/editbox_background"
android:layout_marginLeft="2dip"
android:singleLine="true"
android:ems="5" >
<requestFocus android:layout_width="wrap_content" />
</EditText>
<CheckBox
android:id="#+id/review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/search"
android:layout_alignParentRight="true"
android:layout_marginTop="6dip"
android:layout_alignBaseline="#+id/search"
android:text="Review Item" />
<RelativeLayout
android:id="#+id/header"
android:layout_marginTop="10dip"
android:layout_below="#+id/review"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E5E4E2"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtItemcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Code"
android:singleLine="true"
android:layout_marginLeft="3dip"
android:textStyle="bold"
/>
<TextView
android:id="#+id/txtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/txtItemcode"
android:textStyle="bold"
android:text="Item" />
<TextView
android:id="#+id/txtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="14dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textStyle="bold"
android:text="Quantity" />
</RelativeLayout>
<LinearLayout
android:id="#+id/listlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
android:layout_above="#+id/lastbutton">
<ListView
android:id="#+id/createlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:cacheColorHint="#00000000"
android:divider="#adb8c2"
android:dividerHeight="1dp"
android:scrollingCache="false"
android:smoothScrollbar="true"
>
</ListView>
</LinearLayout>
<RelativeLayout
android:layout_alignParentBottom="true"
android:id="#+id/lastbutton"
android:layout_marginBottom="8dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/createcancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/createsavedraft"
android:background="#drawable/roundedbutton"
android:text=" Cancel " />
<Button
android:id="#+id/createsavedraft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/creatapprove"
android:background="#drawable/roundedbutton"
android:text=" Save Draft " />
<Button
android:id="#+id/creatapprove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/roundedbutton"
android:text=" Approve " />
</RelativeLayout>
my custom xml create_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtItemcode"
android:layout_width="70dip"
android:layout_height="wrap_content"
android:text="323232"
android:singleLine="true"
android:layout_marginTop="9dip"
android:layout_marginLeft="5dip"
android:textStyle="bold"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<TextView
android:id="#+id/txtItem"
android:layout_width="70dip"
android:layout_height="wrap_content"
android:layout_marginTop="9dip"
android:layout_marginLeft="25dp"
android:layout_toRightOf="#+id/txtItemcode"
android:layout_alignBaseline="#+id/txtItemcode"
android:text="5456455565456"
android:focusable="false"
android:focusableInTouchMode="false" />
<EditText
android:id="#+id/editcreateQuantity"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#android:drawable/editbox_background"
android:ems="10"
android:inputType="number"
android:layout_marginRight="5dip"
android:layout_alignBaseline="#+id/txtItemcode"
android:focusable="true"
android:singleLine="true" >
</EditText>
</RelativeLayout>
My java code
public class CreateChallan extends Activity {
ListView lstCreate;
String[] strmainItemCode;
String[] strItem;
String[] strQuantity;
Context context=this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.createchallan);
lstCreate= (ListView) findViewById(R.id.createlist);
lstCreate.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
strmainItemCode= new String[]{"55555551","255555","355555","455555","555555"};
strItem =new String[]{"A","B","C","D","F"};
strQuantity =new String[]{"100","200","30","400","500"};
CreateAdapter adapter= new CreateAdapter(this, strmainItemCode, strItem, strQuantity);
lstCreate.setAdapter(adapter);
lstCreate.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position1, long id) {
// TODO Auto-generated method stub
Toast.makeText(context, "Position", Toast.LENGTH_LONG).show();
}
});
}
// Create List Adapter
class CreateAdapter extends ArrayAdapter<String>
{
TextView txtItecode, txtItem;
EditText editQuantity;
String[] strItecode;
String[] strItem;
String[] strQuantity;
Context context;
CreateAdapter(Context context, String[] strItemcode, String[] strItem, String[] strQauntity)
{
super(context,R.layout.create_list_item,R.id.txtItemcode,strItemcode);
this.context= context;
this.strItecode= strItemcode;
this.strItem= strItem;
this.strQuantity= strQauntity;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View row;
row=mInflater.inflate(R.layout.create_list_item, parent,false);
txtItecode= (TextView) row.findViewById(R.id.txtItemcode);
txtItem =(TextView) row.findViewById(R.id.txtItem);
editQuantity = (EditText) row.findViewById(R.id.editcreateQuantity);
editQuantity.setSelected(false);
txtItecode.setText(strItecode[position]);
txtItem.setText(strItem[position]);
editQuantity.setText(strQuantity[position]);
txtItecode.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "click", Toast.LENGTH_LONG).show();
}
});
return row;
}
}
}
below code on you manifest in TabHostActivity or tab parent activity..
android:windowSoftInputMode="adjustPan"
Hi try below code on you manifest for activity
android:windowSoftInputMode="adjustPan"
hope this will work,Thanks
Is there a way we can have same navigation drawer on each activity but with change in the header text? For instance I got two activities, my home activity will display a header text as home and my "about us" activity will display "about us" header text but all will have the same navigation settings.
BaseActivity
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class BaseActivity extends Activity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
public DrawerLayout drawer;
ImageView navDrawerBtn;
HashMap<String, List<String>> listDataChild;
List<String> listDataHeader;
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
protected LinearLayout fullLayout;
protected FrameLayout actContent;
#Override
public void setContentView(final int layoutResID) {
fullLayout= (LinearLayout) getLayoutInflater().inflate(R.layout.home, null); // Your base layout here
actContent= (FrameLayout) fullLayout.findViewById(R.id.content_frame);
getLayoutInflater().inflate(layoutResID, actContent, true); // Setting the content of layout your provided to the act_content frame
super.setContentView(fullLayout);
// here you can get your drawer buttons and define how they should behave and what must they do, so you won't be needing to repeat it in every activity class
prepareListData();
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
navDrawerBtn = (ImageView)findViewById(R.id.headerDrawer);
expListView = (ExpandableListView) findViewById(R.id.lvExp);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
expListView.setIndicatorBounds(402,465);
} else {
expListView.setIndicatorBoundsRelative(402,465);
}
drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
navDrawerBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(!drawer.isDrawerOpen(expListView)) {
drawer.openDrawer(expListView);
} else {
drawer.closeDrawer(expListView);
}
}
});
//listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
// Listview Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
switch (childPosition) {
case 0:
Intent a = new Intent(getApplicationContext(), MainActivity.class);
startActivity(a);
break;
case 1:
Intent b = new Intent(getApplicationContext(), ScheduleActivity.class);
startActivity(b);
break;
}
return false;
// TODO Auto-generated method stub
}
});
}
/*
* Preparing the list data
*/
protected void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("VRP Medical Bay");
//listDataHeader.add("");
//listDataHeader.add("");
// Adding child data
List<String> listUnderVRP = new ArrayList<String>();
listUnderVRP.add("eDataClinical");
listUnderVRP.add("Schedule");
listUnderVRP.add("Dictate");
listUnderVRP.add("View Messages");
listUnderVRP.add("Reports for Signature");
listUnderVRP.add("View Billing");
listUnderVRP.add("View State");
listDataChild.put(listDataHeader.get(0), listUnderVRP); // Header, Child data
//listDataChild.put(listDataHeader.get(1), nowShowing);
//listDataChild.put(listDataHeader.get(2), comingSoon);
}
}
my home layout
<?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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="73dp"
android:background="#color/actionbar" >
<ImageView
android:id="#+id/headerDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_drawer"
android:contentDescription="#string/desc" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/actionHeaderText"
android:layout_toRightOf="#+id/headerDrawer"
android:src="#drawable/e_icon"
android:contentDescription="#string/desc" />
<TextView
android:id="#+id/actionHeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/actionbar_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="32sp"
android:textStyle="bold"
android:typeface="monospace" />
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="470dp"
android:layout_height="match_parent"
android:groupIndicator="#drawable/group_selector"
android:transcriptMode="alwaysScroll"
android:layout_gravity="start"
android:childDivider="#4abcd7"
android:divider="#626262"
android:dividerHeight="4dp"
android:cacheColorHint="#fff" >
</ExpandableListView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
My Billing Activity:
public class ViewBillingActivity extends BaseActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_billing_test);
}
my billing layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="73dp"
android:background="#color/actionbar" >
<ImageView
android:id="#+id/headerDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/desc"
android:src="#drawable/ic_drawer" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/actionHeaderText"
android:layout_toRightOf="#+id/headerDrawer"
android:src="#drawable/e_icon" />
<TextView
android:id="#+id/actionHeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/view_billing"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:textSize="32sp"
android:textStyle="bold"
android:typeface="monospace" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#color/view_billing_bg"
android:paddingTop="10dp" >
<TextView
android:id="#+id/latestBillingTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/latest_billing"
android:textColor="#color/white"
android:textSize="34sp"
android:textStyle="normal" />
<TextView
android:id="#+id/latestBillingDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/latestBillingTitle"
android:layout_centerHorizontal="true"
android:text="(03/01/2014 - 03/31/2014)"
android:textColor="#color/white"
android:textSize="24sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="720dp"
android:layout_height="820dp"
android:layout_below="#+id/relativeLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:background="#color/white"
android:paddingBottom="50dp" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/relativeLayout7"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#color/view_mssgs_id_bg" >
<TextView
android:id="#+id/vbTxtID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:gravity="center_horizontal"
android:text="024"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="500dp"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:layout_toRightOf="#+id/relativeLayout7"
android:background="#color/tile_box" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/vb_outstanding_balance"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/vbTxTOutBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/textView1"
android:text="0.00"
android:textColor="#color/white"
android:textSize="24sp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout3"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout2"
android:layout_marginTop="4dp"
android:background="#color/tile_box" >
<TextView
android:id="#+id/vbTxtLastMonthBill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/textView1"
android:text="2004.50"
android:textColor="#color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/vbTxtLastMonthBill"
android:layout_alignBottom="#+id/vbTxtLastMonthBill"
android:layout_alignParentLeft="true"
android:layout_marginLeft="11dp"
android:text="#string/vb_last_month_bill"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout4"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout3"
android:layout_marginTop="4dp"
android:background="#color/tile_box" >
<TextView
android:id="#+id/vbTxtPaymentReceived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/textView1"
android:text="2004.50"
android:textColor="#color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/vbTxtPaymentReceived"
android:layout_alignBottom="#+id/vbTxtPaymentReceived"
android:layout_alignParentLeft="true"
android:layout_marginLeft="11dp"
android:text="#string/vb_payments_received"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout5"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout4"
android:layout_marginTop="4dp"
android:background="#color/tile_box" >
<TextView
android:id="#+id/vbTxtPaymentReceivedDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/textView1"
android:text="04/05/2014"
android:textColor="#color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/vbTxtPaymentReceivedDate"
android:layout_alignBottom="#+id/vbTxtPaymentReceivedDate"
android:layout_alignParentLeft="true"
android:layout_marginLeft="11dp"
android:text="#string/vb_payment_received_date"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout6"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout5"
android:layout_marginTop="4dp"
android:background="#color/tile_box" >
<TextView
android:id="#+id/vbTxtBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/textView1"
android:text="1575.75"
android:textColor="#color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/vbTxtBalance"
android:layout_alignBottom="#+id/vbTxtBalance"
android:layout_alignParentLeft="true"
android:layout_marginLeft="11dp"
android:text="#string/vb_balance"
android:textColor="#color/white"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
First of all, according to design guidelines, it is better to set header text within the ActionBar when navigation drawer is open rather than having separate TextView header within navigation drawer layout.
But in case you really-really need separate "header" text within your navigation drawer - layout (and the way you interact with it) for your navigation drawer is exactly the same as any other regular layout you usually have in your activities. Just declare TextView, give it some reasonable id, get this text view in your activity (findViewById()) and set proper text
Write Change Text Code in onDrawerClosed and onDrawerOpened methods according to the text you want to display..
my app needs to display data in a list, I walked through some tutorials and figured out to use a header.xml and row.xml. It works fine but now I would like to add more stuff on my header.xml and I found out that the entire header.xml is scrolling with the row.xml as well, which I dont really want.
Any solution that doesn't require me to rewrite and change my code style completely?
Activity:
public class HistoryActivity extends ListActivity
{
private static final String TAG = "HistoryActivity";
ListView lv;
SimpleAdapter sd;
RecordDAO dao = new RecordDAO(HistoryActivity.this);
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
lv = getListView();
lv.addHeaderView(getLayoutInflater().inflate(
R.layout.header, null, false));
}
#Override
protected void onResume()
{
super.onResume();
ArrayList<Record> Records = new ArrayList<Record>();
Records = (ArrayList<Record>) dao.findAll();
ArrayList<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for (int x = Records.size()-1; x >=0; x--)
{
map = new HashMap<String, String>();
map.put(....// all my data
aList.add(map);
}
sd = new SimpleAdapter(this, aList, R.layout.row,
new String[]
{ "date", "name", "time",
"rating" }, new int[]
{ R.id.date, R.id.name, R.id.time,
R.id.rating});
lv.setAdapter(sd);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3)
{
TextView tx = (TextView) view.findViewById(R.id.date);
String s = tx.getText().toString();
Intent intent = new Intent(HistoryActivity.this, EditRecordActivity.class);
intent.putExtra("date", s);
startActivity(intent);
}
});
}
private void insertNewRecord()
{
dao.add(newRecord);
}
}
header.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="fill_parent"
android:clickable="true"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingTop="4dip" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="name"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Time"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rating"
android:textColor="#FFFFFF"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
row.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingTop="4dip" >
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="1"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/Rating"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF" />
</LinearLayout>
Don't use ListActivity. I think it is a bad practice. Use a regular Activity. Just insert a ListView with an id "#android:id/list" into header.xml.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingTop="4dip" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Date"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="name"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Time"
android:textColor="#FFFFFF"
android:textSize="16dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rating"
android:textColor="#FFFFFF"
android:textSize="16dp" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
And you can get the list reference by doing:
ListView lv = (ListView)findViewById(R.id.list);
Setting the Header of a ListView means that it will be the first item of your list, but still will scroll with the list itself.
In your case, you can create some kind of layout (similar to header.xml) and place it above the ListView.
Instead of ListActivity, extend from Activity
Create a main_layout.xml that define some views and a ListView.
main_layout
<include header.xml/>
<listview>
If you don't want your header and footer views to scroll with your ListView, then make sure that you use the addHeaderView() and addFooterView() BEFORE you call your setAdapter() method. I would recommend moving the setAdapter() method to your onCreate() method.
i am confusing how to play gif image in my layout. my layout using RelativeLayout and the image is at center. i've looking the way to play the gif but the example is not tell me how to implement it to my layout that contains another widget there not only to play the gif alone. please help me to do this.
here is the code:
choosepet_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/background"
android:paddingTop="50px"
android:paddingBottom="10px"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/choose"
android:layout_gravity="center"
android:layout_marginBottom="10px"
/>
<Spinner
android:id="#+id/pet"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:prompt="#string/pettype"
/>
<ImageView
android:id="#+id/petpic"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cat"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10px"
android:paddingLeft="10px">
<RadioGroup
android:orientation="horizontal"
android:id="#+id/genderGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<TextView
android:text="Gender"
android:id="#+id/textGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginBottom="13px"
android:textColor="#000000"
/>
<RadioButton
android:id="#+id/maleRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_toRightOf="#+id/textGender"
/>
<RadioButton
android:id="#+id/femaleRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_toRightOf="#+id/maleRadio"
/>
</RadioGroup>>
<TextView
android:text="Name"
android:id="#+id/textName"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginBottom="11px"
android:layout_above="#+id/genderGroup"
android:textColor="#000000"
android:layout_marginRight="12px"
/>
<EditText
android:id="#+id/name"
android:layout_width="150sp"
android:layout_height="40sp"
android:layout_toRightOf="#+id/textName"
android:layout_above="#+id/genderGroup"
/>
<ImageButton
android:id="#+id/process"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/letsplay"
android:background="#null"
android:layout_toRightOf="#+id/genderGroup"
android:layout_alignParentBottom="true"
android:layout_marginBottom="38px"
/>
</RelativeLayout>
</LinearLayout>
and this is the choosepet.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.choosepet_layout);
Spinner spinnerPet = (Spinner) findViewById(R.id.pet);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.pet_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerPet.setAdapter(adapter);
EditText nameField = (EditText) findViewById(R.id.name);
nameField.requestFocus();
ImageButton processButton = (ImageButton) findViewById(R.id.process);
processButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), petMain.class);
startActivityForResult(myIntent, 0);
}
});
final ImageView imgPet = (ImageView) findViewById(R.id.petpic);
spinnerPet.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?>parent,
View view, int pos, long id){
String petType = parent.getItemAtPosition(pos).toString();
if(petType.equals("Anjing")){
imgPet.setImageResource(R.drawable.dog);
}else{
imgPet.setImageResource(R.drawable.cat);
}
}
#Override
public void onNothingSelected(AdapterView parent) {
// TODO Auto-generated method stub
}
});
}
thank you in advance!
as far as i know android does not support gif animation you have to create the animation by other ways like series of images
like in example linked below
http://yekmer.posterous.com/how-to-make-a-loading-animator-in-android
Android can decode gif format.
take a look at this post.