Shared elements in fragments dont work, textview -> edittext - android

I have 2 fragments, and want to do a shared element transition between them.
The item in an recyclerview, with an adapter, contains a textview that should be animated to an edittext in the next fragment.
The recyclerview is in an fragment too.
Here's my code:
item layout for viewholder from adapter:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row_container"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#FAFAFA"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:elevation="0dp"
>
<RelativeLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#null"
android:elevation="0dp"
android:layout_centerVertical="true"
>
<ImageButton
android:id="#+id/notify_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_bookmark_black_24dp"
android:background="#null"
android:tint="#9E9E9E"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:maxLines="1"
android:ellipsize="end"
android:transitionName="title"
/>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text"
android:layout_below="#id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:textSize="15sp"
android:maxLines="2"
android:layout_alignParentBottom="true"
android:textColor="#android:color/black"
android:ellipsize="end"
android:transitionName="text"
/>
</RelativeLayout>
<ImageView
android:id="#+id/fav"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:visibility="invisible"
android:src="#drawable/ic_star_black_24dp"
/>
</RelativeLayout>
MyAdapter class, the item row click:
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment frag = new Fragment_Notice();
int tin_title = Integer.parseInt(String.valueOf(title.getText().length()));
if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) &&
( SharedPrefHelper.getBool("shared_transition") == true) &&
( tin_title >= 1 ) ) {
//Exit transition for old fragment
frag.setSharedElementReturnTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setExitTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
//Enter transition for new fragment
frag.setSharedElementEnterTransition(TransitionInflater.from(context).inflateTransition(R.transition.title_transform));
frag.setEnterTransition(TransitionInflater.from(context).inflateTransition(android.R.transition.explode));
ft.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.addSharedElement(title, "title")
.commit();
} else {
int open = R.anim.abc_fade_in;
int close = R.anim.abc_fade_out;
ft.setCustomAnimations(open, close, open, close)
.replace(R.id.container, frag, "NoticeTag")
.addToBackStack(null)
.commit();
}
}
});
Layout from final fragment:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:padding="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:nextFocusForward="#id/text"
android:imeOptions="actionNext"
android:singleLine="true"
android:ems="16"
android:hint="#string/title"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:scrollbars="horizontal"
android:transitionName="title"
/>
<EditText
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/text"
android:textColor="#212121"
android:textColorHint="#757575"
android:background="#null"
android:layout_marginLeft="2dp"
android:transitionName="text"
/>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:elevation="0dp"
android:background="#color/grey"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<ImageButton
android:id="#+id/fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_star_black_24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:background="?android:attr/selectableItemBackground"
android:tint="#9E9E9E"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top"
android:id="#+id/snackbar">
</android.support.design.widget.CoordinatorLayout>
The textview doesnt animate to an edittext.
The explode animation appears.
Between activities the animation works.
Any suggestions how to fix?

Related

Clicking on navigation drawer listview item opens unclicked activity every time

I'm implementing a service and receiver in SettingsActivity and when i open the app for the first time there is no issue but once I visit SettingsActivity and come back, closing the navigation drawer from then on opens SettingsActivity everytime even if don't click any item in the listview
This is my MainActivity layout file where i have implemented navigation drawer :-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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=".MainActivity"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/drawer_layout">
<FrameLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical">
<LinearLayout
android:id="#+id/top_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:background="#00AFF0"
android:orientation="vertical">
<TextView
android:id="#+id/ship_name"
android:layout_width="wrap_content"
android:minWidth="120dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#00AFF0"
android:background="#drawable/button_background"
android:padding="10dp"
android:textSize="16sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="10dp">
<ImageButton
android:id="#+id/date_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_reset"
android:background="#android:color/transparent"
android:layout_marginEnd="10dp"
android:visibility="gone"/>
<TextView
android:id="#+id/current_date"
android:layout_width="wrap_content"
android:minWidth="120dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#android:color/white"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textSize="16sp"
/>
<ImageButton
android:id="#+id/date_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_date"
android:background="#android:color/transparent"
android:layout_marginStart="10dp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tickets_layout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/button_border"
android:gravity="center"
android:minWidth="120dp"
android:orientation="horizontal"
android:textColor="#android:color/white">
<TextView
android:id="#+id/ticket_no_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="end|center"
android:padding="2dp"
android:text=""
android:textColor="#FFFF00"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="2dp"
android:gravity="center_vertical"
android:text="#string/tickets"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="16sp" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#android:color/white" />
<TextView
android:id="#+id/no_of_people_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="end|center"
android:padding="2dp"
android:textSize="16sp"
android:textColor="#FFFF00" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="2dp"
android:text="#string/people"
android:textSize="16sp"
android:textAllCaps="true"
android:gravity="center_vertical"
android:textColor="#android:color/white" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_no_data"
android:gravity="center|center_horizontal"
android:textSize="18sp"
android:textColor="#color/textColor"
android:textStyle="bold"
android:visibility="gone"
android:paddingTop="15dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/search_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<EditText
android:id="#+id/ticket_no"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.8"
android:layout_marginStart="20dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:background="#drawable/edittextbackground"
android:imeOptions="actionDone"
android:paddingStart="10dp"
android:paddingEnd="0dp"
android:maxLength="19"
android:inputType="number"
android:digits="01234 56789"
android:maxLines="1"
/>
<Button
android:id="#+id/search_ticket_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginEnd="20dp"
android:layout_weight="0.2"
android:textColor="#android:color/white"
android:text="#string/go"
android:textSize="16sp"
android:textAllCaps="true"
android:background="#drawable/go_button_shape"/>
</LinearLayout>
<LinearLayout
android:id="#+id/or_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="30dp"
android:orientation="horizontal"
android:paddingRight="30dp">
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:background="#android:color/black"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:text="#string/or"
android:textSize="20sp"
android:gravity="center"/>
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:background="#android:color/black"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/scan_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="0.5">
<Button
android:id="#+id/scanQr"
android:layout_width="wrap_content"
android:minWidth="120dp"
android:layout_height="40dp"
android:text="#string/scan_qr"
android:layout_gravity="center|top"
android:gravity="center"
android:textColor="#android:color/white"
android:background="#drawable/scan_button"
android:padding="10dp"
android:layout_marginTop="10dp"
android:textSize="16sp"
/>
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/scanner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:id="#+id/scan_results"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="50dp"
android:layout_marginBottom="10dp"
android:visibility="visible"
android:textStyle="bold"
android:textSize="18sp"
android:gravity="left"
android:layout_marginStart="20dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:paddingStart="10dp"
android:paddingEnd="0dp"
/>
</LinearLayout>
<TextView
android:id="#+id/no_trips_tv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#android:color/darker_gray"
android:textSize="18sp"
android:text="#string/no_trips"
android:visibility="gone"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/layout_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:alpha="0.5"
/>
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFF"
android:choiceMode="singleChoice"
/>
</android.support.v4.widget.DrawerLayout>
And in my MainActivity i handle item click events like this where navList is Listview and drawer is DrawerLayout :-
navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id){
drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
#Override
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
if (position == 0){
} else if(position == 1)
{
getTicketsInfo(Helper.getValueFromSharedPreferences("shipId",getApplicationContext()),currentDate);
} else if(position == 2) {
submitTickets();
} else if(position == 3) {
Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(settingsIntent);
} else {
Helper.removeKeyStoredinSharedPreferences("sessionHandle", getApplicationContext());
finish();
}
}
});
drawer.closeDrawer(navList);
}
});
remove drawer.setDrawerListener and place the code directly inside onItemClick
drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position)
{
case:0
{
break;
}
case:1
{
getTicketsInfo(Helper.getValueFromSharedPreferences("shipId",getApplicationContext()),currentDate);
break;
}
case:2
{
submitTickets();
break;
}
case:3
{
Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(settingsIntent);
break;
}
case:4{
Helper.removeKeyStoredinSharedPreferences("sessionHandle", getApplicationContext());
finish();
break;
}
default:
}
}
});
drawer.closeDrawer(navList);
}

EditText OnFocusChangeListener() doesn't hide cursor and view

I made an EditText OnFocusChangeListener that supposedly hides the cursor and another view when it's not in focus (i.e. clicking anywhere on the screen aside from the EditText will hide those items). Clicking on the EditText is the only time that will display them.
This is my OnFocusChangeListener for my EditText pageTitle:
pageTitle.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if(b) {
pageTitle.setCursorVisible(true);
saveCancelBar.setVisibility(View.VISIBLE);
} else {
pageTitle.setCursorVisible(false);
saveCancelBar.setVisibility(View.GONE);
}
}
});
I also made an OnclickListener:
pageTitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pageTitle.setCursorVisible(true);
saveCancelBar.setVisibility(View.VISIBLE);
}
});
The OnClickListener works but not the OnFocusListener. Ideally, pageTitle's cursor and saveCancelBar are initially hidden and will only appear when pageTitle is clicked.
This my XML code:
<?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"
tools:ignore="missingPrefix"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context="app.wanderast.activity.AddPhotoActivity">
<LinearLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal">
<TextView
android:id="#+id/back_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/arrow_left"
android:textSize="20sp"
android:clickable="true"
android:textColor="#color/black" />
</LinearLayout>
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_below="#id/toolbar"
android:orientation="vertical">
<EditText
android:id="#+id/title"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:background="#color/transparent"
android:maxLength="64"
android:privateImeOptions="nm"
android:inputType="textNoSuggestions|textMultiLine"
android:cursorVisible="false"
app:autoSizeTextType="uniform"
app:autoSizeMinTextSize="16sp"
app:autoSizeMaxTextSize="24sp"
app:autoSizeStepGranularity="4sp"
android:textColor="#color/grey700"/>
<View
android:layout_width="100dp"
android:layout_height="2dp"
android:layout_marginTop="3dp"
android:background="#color/grey700"
/>
<LinearLayout
android:id="#+id/sort"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:layout_marginTop="20dp"
android:clickable="true"
android:gravity="bottom"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="#+id/sort_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:text="List View"
android:textColor="#color/grey700"
android:textSize="14sp"/>
<TextView
android:id="#+id/sort_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chevron_circle_down"
android:textColor="#color/grey700"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/add_photo_layout"
android:layout_marginTop="150dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_centerInParent="true">
<TextView
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:layout_marginBottom="30dp"
android:background="#null"
android:minLines="0"
android:text="Add your first travel moment to your story"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:id="#+id/capture_photo_button"
android:layout_marginBottom="15dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center|center_vertical"
android:background="#drawable/green_pill_thick">
<TextView
android:id="#+id/capture_photo_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/camera"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/green500"
android:layout_marginEnd="5dp"/>
<TextView
android:id="#+id/capture_photo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture Moment"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/green500"
android:textAlignment="center"
android:textSize="14sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/add_photo_button"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center|center_vertical"
android:background="#drawable/blue_pill_thick">
<TextView
android:id="#+id/add_photo_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/photo"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/blue500"
android:layout_marginEnd="5dp"/>
<TextView
android:id="#+id/add_photo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add from Gallery"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/blue500"
android:textAlignment="center"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/list_view_layout"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="150dp"
android:paddingBottom="50dp">
<ListView
android:id="#+id/list_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll">
</ListView>
</RelativeLayout>
</LinearLayout>
<!--Navbar-->
<LinearLayout
android:id="#+id/photo_story_navbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#drawable/navbar"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:visibility="gone">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingStart="15dp"
android:orientation="horizontal"
android:layout_marginEnd="10dp">
<!-- Take Photo Button -->
<LinearLayout
android:id="#+id/nav_capture_button"
android:layout_width="84dp"
android:layout_height="32dp"
android:paddingStart="10dp"
android:orientation="horizontal"
android:background="#drawable/green_pill_button"
android:layout_gravity="center_vertical"
android:gravity="center|center_vertical"
android:paddingEnd="10dp"
android:clickable="true">
<TextView
android:id="#+id/nav_capture_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="#string/camera"
android:textColor="#color/green500"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingEnd="5dp"/>
<TextView
android:id="#+id/nav_capture_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/green500"
android:textAlignment="center"
android:textSize="12sp"/>
</LinearLayout>
<!-- Add from Gallery Button -->
<LinearLayout
android:id="#+id/nav_gallery_button"
android:layout_width="84dp"
android:layout_height="32dp"
android:paddingStart="10dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal"
android:background="#drawable/blue_pill"
android:layout_gravity="center_vertical"
android:gravity="center|center_vertical"
android:paddingEnd="10dp"
android:clickable="true">
<TextView
android:id="#+id/nav_gallery_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="#string/photo"
android:textColor="#color/blue500"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingEnd="5dp"/>
<TextView
android:id="#+id/nav_gallery_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gallery"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/blue500"
android:textAlignment="center"
android:textSize="12sp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:paddingEnd="15dp"
android:orientation="horizontal">
<!-- Review button -->
<LinearLayout
android:id="#+id/nav_review_button"
android:layout_width="84dp"
android:layout_height="32dp"
android:paddingStart="10dp"
android:orientation="horizontal"
android:background="#drawable/red_500_pill"
android:layout_gravity="right"
android:gravity="center|center_vertical"
android:paddingEnd="10dp"
android:clickable="true">
<TextView
android:id="#+id/nav_review_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Review"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/red500"
android:textAlignment="center"
android:textSize="12sp"/>
<TextView
android:id="#+id/nav_review_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="#string/angle_double_right"
android:textColor="#color/red500"
android:layout_gravity="center_horizontal|center_vertical"
android:paddingStart="5dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/save_cancel_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/linearLayout"
android:layout_alignParentStart="true"
android:background="#drawable/black_border_top"
android:visibility="gone">
<RelativeLayout
android:id="#+id/save_title_btn"
android:clickable="true"
android:layout_width="84dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:background="#drawable/blue_pill"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="fill"
android:text="Save Title"
android:textSize="12sp"
android:textColor="#2196F3"/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/cancel_title_btn"
android:layout_width="84dp"
android:layout_height="32dp"
android:clickable="true"
android:layout_alignParentRight="true"
android:background="#drawable/grey_700_pill"
android:layout_marginRight="105dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Cancel"
android:layout_gravity="fill"
android:textSize="12sp"
android:textColor="#616161" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
If you check the definition of onFocusChange(View v, boolean hasFocus) you will notice that your code must change like this:
pageTitle.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(!hasFocus) {
pageTitle.setCursorVisible(true);
saveCancelBar.setVisibility(View.VISIBLE);
} else {
pageTitle.setCursorVisible(false);
saveCancelBar.setVisibility(View.GONE);
}
}
});
This is the code for checking the soft keyboard visibility in Android
public class MainActivity extends AppCompatActivity
{
public static String TAG = MainActivity.class.getSimpleName();
private TextView saveCancelBar;
private EditText pageTitle;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListenerToRootView();
saveCancelBar = (TextView) findViewById(R.id.cancel_bar);
pageTitle = (EditText) findViewById(R.id.title);
pageTitle.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View view, boolean hasFocus)
{
...
}
});
}
public void setListenerToRootView()
{
final View activityRootView = getWindow().getDecorView().findViewById(android.R.id.content);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
#Override
public void onGlobalLayout()
{
Rect r = new Rect();
activityRootView.getWindowVisibleDisplayFrame(r);
int screenHeight = activityRootView.getRootView().getHeight();
// r.bottom is the position above soft keypad or device button.
// if keypad is shown, the r.bottom is smaller than that before.
int keypadHeight = screenHeight - r.bottom;
Log.e(TAG, "keypadHeight = " + keypadHeight);
if (keypadHeight > screenHeight * 0.15) {
// 0.15 ratio is perhaps enough to determine keypad height.
Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboard open", Toast.LENGTH_SHORT).show();
} else {
// keyboard is closed
Toast.makeText(getApplicationContext(), "Gotcha!!! softKeyboard closed", Toast.LENGTH_SHORT).show();
saveCancelBar.setVisibility(View.GONE);
}
}
});
}
}
I think you forgot to add focusableInTouchMode. Add focusableInTouchMode to your editText to get focused on touching the view.
android:focusableInTouchMode="true"

Android - I want Navigation button and viewpager do the same function

I am working in project that contain framelayout display fragments by navigation button next , back and I provide it method below in my code till now every thing works great
here is why I am here , I need make the same function done with navigation button done with swipe button , I add viewpager and pass all fragment to adapter but it give me different view overlapping
Fragment mFragmentsList[] = new Fragment[]{new Slide2Frag() , .... new Slide23Frag()};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here is what I need to add viewpager
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentsList);
mViewPager.setAdapter(adapter);
DisplayFragment(count);
}
// display fragment method
private void DisplayFragment(int display) {
Fragment fragment = null;
switch (display) {
case 2:
fragment = new Slide2Frag();
break;
}
FragmentManager mFragmentManager = getSupportFragmentManager();
FragmentTransaction mTransaction = mFragmentManager.beginTransaction();
mTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
mTransaction.replace(R.id.container, fragment).commit();
}
private void NextMethod() {
if (count < 23) {
count++;
} else {
count = 2;
}
DisplayFragment(count);
}
private void backMethod() {
if (count > 2) {
count--;
} else {
count = 23;
}
DisplayFragment(count);
}
my xml code
<?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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/headerlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/home_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="right"
android:layout_marginEnd="219dp"
android:layout_marginRight="219dp"
android:adjustViewBounds="true"
android:background="#drawable/home" />
<ImageView
android:id="#+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:adjustViewBounds="true"
android:background="#drawable/close" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="300dp"
android:layout_height="120dp"
android:layout_marginLeft="25dp"
android:adjustViewBounds="true"
android:background="#drawable/aciloc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="370dp"
android:layout_height="50dp"
android:layout_below="#+id/home_btn"
android:layout_marginBottom="10dp"
android:layout_toEndOf="#+id/imageView3"
android:layout_toRightOf="#+id/imageView3"
android:adjustViewBounds="true"
android:background="#drawable/leadingppi"
android:scaleType="centerInside" />
</RelativeLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_above="#+id/footer_layout"
android:layout_below="#+id/headerlayout" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<LinearLayout
android:id="#+id/footer_layout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:weightSum="6">
<ImageButton
android:id="#+id/left_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/left_back"
android:scaleType="centerInside" />
<Button
android:id="#+id/ac20"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 20mg" />
<Button
android:id="#+id/ac40"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="Aciloc 40mg" />
<Button
android:id="#+id/profile"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="PROFILE" />
<Button
android:id="#+id/indications"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="INDICATIONS & DOSAGE" />
<Button
android:id="#+id/pack"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#drawable/btn_background"
android:textColor="#color/text_color"
android:text="UNIQUE PACK" />
<ImageButton
android:id="#+id/right_nav"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_marginLeft="50dp"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:background="#drawable/right_back"
android:scaleType="centerInside"
android:textColor="#color/text_color"/>
</LinearLayout>
</RelativeLayout>
here is image explain

How to remove list view item in list view android?

In my application i have one custom list view. whenever i click the close image list item, the list item layout must be removed with space. i used visibility:gone attribute, the list item layout deleted but the space is visible. I am using listview in scroll view ,,that was also not working....please help me out.
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.recharge_listitem, null);
TextView accountnumber = (TextView) convertView
.findViewById(R.id.accountnumber);
TextView servicename = (TextView) convertView
.findViewById(R.id.servicetypname);
TextView planamount = (TextView) convertView
.findViewById(R.id.rechargeamount);
final ImageView close = (ImageView) convertView
.findViewById(R.id.crosse_close_img);
final LinearLayout layoutrecharge=(LinearLayout)convertView.findViewById(R.id.rechargelay);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
layoutrecharge.setVisibility(View.GONE);
}
});
accountnumber.setText("Rs."+bpData.get(position).getAccountNumber());
servicename.setText(bpData.get(position).getServicename());
planamount.setText(bpData.get(position).getRechargeamount());
return convertView;
}
}
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="match_parent"
android:background="#drawable/background">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e365a">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:text="PAYMENT"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:text="Your Recharges"
android:textColor="#1e365a"
android:textSize="20dp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#drawable/dottedline_view" />
<ListView
android:id="#+id/recharge_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</ListView>
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginTop="12dp"
android:background="#1e365a" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Amount to be Paid"
android:textColor="#1e365a"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Rs.130"
android:textColor="#1e365a"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="#+id/ev_b_dob"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bt_apply"
style="#style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="20"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp">
<CheckBox
android:id="#+id/cb_reload_cash"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay using Reload Cash"
android:textColor="#1e365a"
android:textSize="20dp"
android:layout_marginLeft="12dp"/>
</LinearLayout>
<Button
android:id="#+id/atmdebit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="ATM/DEBIT/CREDIT"
android:textColor="#ffffff"
android:textSize="20dp"/>
<Button
android:id="#+id/netbankng_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="NET BANKING"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
please help me.
custom listview item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rechargelay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/accountnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8008505106" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="(" />
<TextView
android:id="#+id/servicetypname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vodafone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=")" />
</LinearLayout>
<TextView
android:id="#+id/rechargeamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RS.30"
android:layout_weight="1" />
<ImageView
android:id="#+id/crosse_close_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/close"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Set View.GONE for View is not right way to remove row from ListView. to remove row remove select row item from Adapter data-source and call notify data change method of adapter to populate changes:
close.setTag(position);
close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int deletePos=Integer.parseInt(v.getTag().toString());
bpData.remove(deletePos);
notifyDataSetChanged();
}
});
Set visibility View.GONE of SCROLL VIEW or other parent of list view....

left and right alignment rows inside Listview?

My goal is below image
And i have below codes
row_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/me"
android:layout_gravity="right"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggghyjkljgfdgjlkhfdhklggg" />
</LinearLayout>
</LinearLayout>
row_left.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:background="#drawable/you"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggggg" />
</LinearLayout>
</LinearLayout>
main.xml
<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="#FFFFFF" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_weight="1"
android:scrollbars="vertical"
android:divider="#null"
android:dividerHeight="0dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/content"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:autoText="false"
android:capitalize="none"
android:ems="10"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="16sp"
android:hint="Enter text"
>
</EditText>
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
</LinearLayout>
but my result become
How i can Fix it?
UPDATE1
my listAdapter.java
public class ListAdapter1 extends BaseAdapter {
private LayoutInflater myInflater;
private List<SmsInformation> list;
public ListAdapter1(Context context) {
myInflater = LayoutInflater.from(context);
}
public void setData(List<SmsInformation> list2) {
this.list = list2;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
if (list.get(position).getTypeOfSms().equals("send"))
convertView = myInflater.inflate(R.layout.raw_left, null);
else
convertView = myInflater.inflate(R.layout.raw_right, null);
holder = new ViewHolder();
holder.message = (TextView) convertView.findViewById(R.id.message);
holder.dateAndTime = (TextView) convertView.findViewById(R.id.dataAndTime);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.message.setText(list.get(position).getMessageContent());
holder.dateAndTime.setText(list.get(position).geTime()+list.get(position).getDate());
return convertView;
}
static class ViewHolder {
TextView message;
TextView dateAndTime;
}
}
Changes made:
~ in row_right.xml & row_left.xml, layout_width attribute of the parent LinearLayout should be set to wrap_content instead of match_parent
~ in main.xml, layout_width attribute of ListView should be set to match_parent. not wrap_content
Try the following code:
~ row_right.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/me"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggghyjkljgfdgjlkhfdhklggg" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
~ row_left.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/you"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#000000"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/dataAndTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="15sp"
android:textColor="#001199"
android:text="gggggggggg" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
~ main.xml
<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="#FFFFFF" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:scrollbars="vertical"
android:divider="#null"
android:dividerHeight="0dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/content"
android:layout_width="253dp"
android:layout_height="wrap_content"
android:autoText="false"
android:capitalize="none"
android:ems="10"
android:scrollHorizontally="true"
android:singleLine="true"
android:textSize="16sp"
android:hint="Enter text"
>
</EditText>
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
</LinearLayout>
Just a guess. in main.xml change width of your ListView to match_parent.
Also add appropriate weight to the layout containing EditText and button. Now the whole space will be assigned to the listView.

Categories

Resources