I have an application in which I am using a list view
setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1,titles));
now what I get is like this
as you can see when I press on the text it senses it and not anywhere on the row beyond that.Is there any way I can work this thing out other than using my custom xml file(resource) for list.
Xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MovieCritics" >
<fragment class="com.example.moviecritics.FragmentMovieName"
android:id="#+id/movie_name"
android:name="android.support.v4.app.ListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
and it's working fine in landscape mode
Try android:listSelector in your ListView
Related
I have a very simple listview, but now it shoes all empty when open it, I wanna user see the light grey lines in this empty list view to let them know this is something will list, Is there any way to show the lines when the listview still empty please?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.anna.DiscoverActivity">
<android.support.v7.widget.SearchView
android:id="#+id/searchview"
app:queryHint="Search HoodMark"
android:background="#color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:layout_below="#id/searchview"
android:id="#+id/discover_list"
android:divider="#color/colorAccent"
android:dividerHeight="4px"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>`
Yes there is. Create an emptyView, design it as you like then supply it to the your adapter. Like this:
//inflate your empty view
View emptyView=getLayoutInflater().inflate(R.layout.emptyViewLayout,null,false);
//set to your listView
listView.setEmptyView(emptyView);
I used SwipeMenuListView from github It works but Views are not consistent as in the picture
Activity layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.robo.lolita.swipemenurecyclerview.MainActivity">
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
this is simple layout swipe menu layout
<?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="#android:color/holo_blue_bright">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/count"/>
</LinearLayout>
SwipeMenuCreator creator = new SwipeMenuCreator() {
public void create(SwipeMenu menu) {
SwipeMenuItem deleteItem = new SwipeMenuItem(
getApplicationContext());
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
0x3F, 0x25)));
deleteItem.setWidth(dp2px(90));
deleteItem.setIcon(R.drawable.camera_icn);
menu.addMenuItem(deleteItem);
I need to attach delete button to the item of listview on Swipe. this swipe menu with delete button. i want to delete the item on clicking the delete button but views are inconsistent in swipemenulistview. Any help to acheive this. Well i cannot do swipe to dismiss and i know we should not mimic the UI of other platforms. but this is the requirement .
I'm thinking of making an app's first view like this: it's just a basic search view with one EditText and two Button on it. I want the background image zooming in and out when user stay on this view, typing or doing nothing.
So I add zoomin.xml and set the animation to the view. Zooming is working but only problem is that it's zooming everything. I know it's because I set background image in the root element of the xml, but I don't know how to make it ONLY zoom in the background picture without affecting other views.
Here's my background image code in root element.
<LinearLayout
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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#drawable/bcg2"
android:orientation="vertical"
android:gravity="center">
So I'm thinking if any floating view will do this? But I don't know how to do it. Or any other suggestion?
Thanks!
Use a fullscrean ImageView instead of the background attribute of the Linearlayout and zoom only the image
<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">
<ImageView
android:id="#+id/image_to_zoom"
android:src="#drawable/bcg2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center"/>
</RelativeLayout>
I have 2 files in the res.
Activity_main.xml is
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test2.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.test2.MainActivity$PlaceholderFragment" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
I plan to change the layout where I problem in this current layout when I drag and drop all item just overlap on each other how to make a nice form type layout? What adjustment and which file must I adjust?
It sounds like you are using the Eclipse GUI tools to create your layout. I strongly suggest that you read about Android Layouts. If you want, you can edit the XML layout text directly or at the very least this will help you understand the properties you can set for your controls to get the exact look that you want.
In the Main Layout I have a ViewFlipper with two ListView inside, follows an excerpt.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/chinese_background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
[...]
<ViewFlipper
android:id="#+id/vFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textStatus"
android:layout_below="#+id/buttonSearch" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/lstVocab01"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/lstVocab02"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</ViewFlipper>
[...]
I inflate the same item layout inside both the ListView exploiting the same CursorAdapter (I am retrieving data from a database). Follows the item 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" >
<TextView
android:id="#+id/textLine01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textSize="#dimen/text_big" />
<TextView
android:id="#+id/textLine02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textSize="#dimen/text_normal" />
</LinearLayout>
As in the Main Layout, there is nothing that change styles or anything related. The adapter does nothing except inflating the DB fields inside the proper TextViews.
There is no difference in the way I update the two cursors. Given CursorAdapterVocabulary adapter_c; and CursorAdapterVocabulary adapter_e; correctly instantiated and correctly working.
adapter_c.changeCursor(cursor);
adapter_c.notifyDataSetChanged();
if (viewFlipper.getDisplayedChild() == 1) {
viewFlipper.setInAnimation(this, R.anim.in_from_left);
viewFlipper.setOutAnimation(this, R.anim.out_to_right);
viewFlipper.showPrevious();
}
[...]
adapter_e.changeCursor(cursor);
adapter_e.notifyDataSetChanged();
if (viewFlipper.getDisplayedChild() == 0) {
viewFlipper.setInAnimation(this, R.anim.in_from_right);
viewFlipper.setOutAnimation(this, R.anim.out_to_left);
viewFlipper.showNext();
}
But: the first ListView is well visibile. The second view has a sort of alpha transparency, which I couldn't remove even forcing alpha to 1.
Please not that:
The rest of the code works perfectly, ListView are updated every time with correct data
It is not a problem of ViewFlipper, I used to have this problem also when I did the runtime replacing of the ListView
I don't have this problem if I use the second ListView in another Activity
The issue is Android Version/Device independent (tried on Samsung SPlus 2.3.6, SIII 4+, Emulator 4.3.0)
This is an image of the difference between the two views, I am filling them with data from a Chinese Vocabulary:
I don't know anymore what to try. Please ask me more details if needed.