ListFragment Textview unnecessary lines - android

ListFragment generates the following view :
I am trying to eliminate the white lines and nothing has helped so far. Any suggestions?
Layout code:
<TextView xmlns:android= " http: //schemas.android.com/apk/res/android"
android:id="#+id/Genere_list"
android:textAppearance="?android:attr/listViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:textColor="#android:color/white" />
The code used to create the view:
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
R.layout.test_album_view, Generes.GENERE_TITLES));
}

#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getListView().setDivider(null);
setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.test_album_view, Generes.GENERE_TITLES));
}

You need to create an ListView.xml like the following:
<?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" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#f19000"
android:dividerHeight="1dip" >
</ListView>
</LinearLayout>
What you want to change are these lines:
android:divider="#f19000"
android:dividerHeight="1dip"
You can also use
android:divider="#android:color/transparent"
to make your lines transparent.

As said, you have to use this:
android:divider="#null"
android:dividerHeight="0dp"
In ListView:
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="0dp">
</ListView>

Related

WearableListView is always null when I changed my wear layout to WatchViewStub from BoxInsetLayout

I have an app that was using BoxInsetLayout but the round layout wasn't working out so I have to change it to WatchViewStub.
I changed to code so that it uses either a round layout or a square layout and that works find. There was a WearableListView inside the original layout file which was just one file. Now it is 3 files, the main one, and the round or square one. Now the listview is always null even though there are no compile time errors.
My onCreate in the main activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_select);
WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub watchViewStub) {
mRectangleBackground = (RelativeLayout) findViewById(R.id.rectLayout);
mRoundBackground = (RelativeLayout) findViewById(R.id.roundLayout);
}
});
WearableListView listView = (WearableListView) findViewById(R.id.list); // this is always null
listView.setHasFixedSize(true);
listView.setAdapter(new SportAdapter(this));
listView.setClickListener(this);
}
My view select xml file (the WatchViewStub)
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub 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"
app:rectLayout="#layout/view_select_square"
app:roundLayout="#layout/view_select_round"
android:keepScreenOn="true"
android:id="#+id/stub"
android:background="#color/green_forest">
</android.support.wearable.view.WatchViewStub>
The square layout
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
app:layout_box="all"
android:id="#+id/rectLayout">
<TextView
android:id="#+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif-thin"
android:paddingBottom="5dp"
android:text="#string/text_select_sport"
android:textColor="#color/white"
android:textSize="26sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text_title"
android:background="#color/white"
android:padding="4dp">
<android.support.wearable.view.WearableListView
android:layout_centerInParent="true"
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:dividerHeight="0dp"/>
</RelativeLayout>
</RelativeLayout>
Whenever I call listView anything like setAdapter, setHasFixedSize, I get a null reference error. Why is my listView always null?
Here is the xml file when it was BoxInsetLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:id="#+id/parent"
android:background="#color/green_forest">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
app:layout_box="all">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_title"
android:text="#string/text_select_sport"
android:textSize="26sp"
android:textColor="#color/white"
android:fontFamily="sans-serif-thin"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:paddingBottom="5dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:padding="4dp"
android:layout_below="#+id/text_title">
<android.support.wearable.view.WearableListView
android:layout_centerInParent="true"
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
android:dividerHeight="0dp"/>
</RelativeLayout>
</RelativeLayout>
</android.support.wearable.view.BoxInsetLayout>
and the main activity before any changes
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_select);
WearableListView listView = (WearableListView) findViewById(R.id.list);
listView.setHasFixedSize(true);
listView.setAdapter(new SportAdapter(this));
listView.setClickListener(this);
}
So I fixed it by adding another method loadAdapter like this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_select);
WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub watchViewStub) {
mRectangleBackground = (RelativeLayout) findViewById(R.id.rectLayout);
mRoundBackground = (RelativeLayout) findViewById(R.id.roundLayout);
listView = (WearableListView) findViewById(R.id.list);
loadAdapter();
}
});
}
private void loadAdapter() {
listView.setHasFixedSize(true);
listView.setAdapter(new SportAdapter(this));
listView.setClickListener(this);
}
as seen in this example here https://gist.github.com/PomepuyN/c30760eaee1e58fdd8fa
ugh...

How to apply custom font to my ListView items?

This my main java code:
public class MainActivity extends ActionBarActivity {
String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry","WebOS","Ubuntu"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, mobileArray);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
}
}
My activity_main.xml file:
<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:orientation="vertical"
android:background="#ffff"
tools:context=".ListActivity" >
<ListView
android:id="#+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
my activity_listview.xml file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold"
android:textColor="#0060FF">
</TextView>
1.First make Custom ArrayAdapter
2.In custom ArrayAdaper override getView()
3.inflate TextView Layout in it.
4. Assign Your Custom Font which is in Your asset Folder
Typeface font1=Typeface.createFromAsset(getAssets(), "/fonts/UNDERCOV.ttf");
button_1=(Button)findViewById(R.id.button1);
button_1.setTypeface(font1);

listView Centered in a dialog in Android

I am trying to have the content of the ListView centered when displayed in a dialog.
This is my code to show the ListView
String[] myItems = {"item1", "item2", "item3"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, R.layout.setting_layout, myItems);
ListView list = (ListView) deleteDialog.findViewById(R.id.listView1);
list.setAdapter(adapter);
list.setFadingEdgeLength(5);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paret, View viewClicked, int position, long id) {
// TODO Auto-generated method stub
}
}
And this is the xml part:
TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_gravity="center"
android:textSize="25sp"
and this is the layout of delete dialog:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:dividerHeight="5dp"
android:gravity="center">
</ListView>
Its running but the content is always displayed to left.
I tried this: How to set the text at center in ListView android application?
but it didn't work.
Hope anyone can guide me through.
this will work for u
<?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="wrap_content" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:dividerHeight="5dp"
android:gravity="center">
</ListView>
You can try with
android:layout_gravity="center_vertical|center_horizontal"
I hope it helps
Change your LinearLayout to:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal">

sliding menu using jfeinstein10 library

I created a sample application to test how sliding menu works. Shown below in the screenshot is what i get as of now. But when I click on the categories button (shown in image below) I should get a secondary menu as shown in the zomato app's screenshot below. How can I do this ? Am I proceeding in the correct way or not?
my SlidingFragmentActivity :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
con = this;
setSlidingActionBarEnabled(false);
setContentView(R.layout.main);
sm = getSlidingMenu();
sm.setMode(SlidingMenu.RIGHT);
sm.setShadowDrawable(R.drawable.shadowright);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
sm.setBehindScrollScale(1.0f);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.5f);
//sm.setSecondaryMenu(R.layout.properties);
//sm.setSecondaryShadowDrawable(R.drawable.shadow);
setTitle("Sliding Bar");
// set the Behind View
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager()
.beginTransaction();
mFrag = new SampleListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
}
my SampleListFragment :
public class SampleListFragment extends SherlockFragment {
private static final String[] Radio_buttons = new String[] { "Distance",
"Rating" };
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list, container, false);
ListView radio_list = (ListView) view.findViewById(R.id.RadioList);
Button categories = (Button) view.findViewById(R.id.sampleButton);
radio_list
.setAdapter(new ArrayAdapter<String>(MainActivity.con,
android.R.layout.simple_list_item_single_choice,
Radio_buttons));
radio_list.setItemsCanFocus(true);
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
categories.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
MainActivity.sm.showSecondaryMenu();
}
});
return view;
}
}
main.xml
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Sliding menu demo...!!!" />
</RelativeLayout>
menu_frame.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
list.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SEARCH"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:id="#+id/searchTextLayout"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_marginBottom="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip" >
<ImageButton
android:id="#+id/searchTextButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#685E5C"
android:scaleType="fitCenter"
android:src="#drawable/abs__ic_search" />
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/searchTextButton"
android:background="#drawable/background_black_border_full"
android:padding="8dp"
android:textColor="#android:color/white" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SORT BY"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="134dp" >
<ListView
android:id="#+id/RadioList"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
<Button
android:id="#+id/sampleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Categories" />
</LinearLayout>
</ScrollView>
SlidingMenu does NOT do this, zomato uses a custom implementation.
SlidingMenu will let you have a menu on the left and the right, but not two on either side.
I would look at using a view pager or a custom implementation. EitherWay I don't know of anything out of the box to do this. I might be worth looking at Android Views for inspiration.
It's a bit late, but still let me post my answer in case it will help someone in future. If you want to show another menu you can use
setMode(SlidingMenu.LEFT_RIGHT);
setSecondaryMenu(R.layout.yourSecondMenu);
and in your button click
showSecondaryMenu(true);
and perform your actions in that class.

Using OnItemClickListener on ListView inside TabActivity

I am having a silly problem with a OnItemCliskListener for my ListView. It works well when the XML is very simple but after I improve its complexity, the OnItemCliskListener stop working
In other words, I have a ListView with just a TextView. But if I turn my ListView into a more complex list with other TextView, an Icon a CheckBox, the ClickListener stop working.
If I run exactly the same code changing just the XML, the OnItemCliskListener stops working. I would be rather grateful if you could help me
WORKING LIST VIEW:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent">
<TextView android:id="#+id/title"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/appCheck"
android:layout_toRightOf="#+id/appIcon"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
</RelativeLayout>
NOT WORKING LISTVIEW:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent">
<ImageView android:src="#drawable/icon" android:id="#+id/appIcon"
android:layout_width="30px" android:layout_height="40px"></ImageView>
<CheckBox android:id="#+id/appCheck"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true"></CheckBox>
<TextView android:id="#+id/title"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/appCheck"
android:layout_toRightOf="#+id/appIcon"
android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
<TextView android:id="#+id/subtitle"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_toLeftOf="#+id/appCheck"
android:layout_toRightOf="#+id/appIcon" android:layout_below="#+id/title"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
</RelativeLayout>
MY JAVA ACTIVITY:
public class MyTabsActivity extends TabActivity implements OnTabChangeListener {
private static final String LIST3_TAB_TAG = "List3";
private RelativeLayout layoutTab3;
private MyArrayAdapter adapterListViewTab3;
private TabHost tabHost;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost();
tabHost.setOnTabChangedListener(this);
...
...
// ----------------- BUILD TAB3
// That is my Tab of Running App
layoutTab3 = (RelativeLayout) findViewById(R.id.running_app_relative_layout);
// Fill my ListView of Running App
ListView runningAppList = (ListView) findViewById(R.id.running_app_listview);
List<String> list3Strings = new ArrayList<String>();
list3Strings.add("Item 1");
list3Strings.add("Item 2");
list3Strings.add("Item 3");
list3Strings.add("Item
adapterListViewTab3 = new MyArrayAdapter(this, android.R.layout.simple_list_item_1, list3Strings);
runningAppList.setAdapter(adapterListViewTab3);
// ????????????????????????????????????????????????????????????????????????????????????????????
// >>>>>>>>>>>> THIS OnItemClickAdapter DOESN'T WORK !!!!! WHY ????????
runningAppList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MyTabsActivity.this, "EUREKA", Toast.LENGTH_SHORT).show();
}
});
...
// add Tab3
TabSpec tab3 = tabHost.newTabSpec(LIST3_TAB_TAG).setIndicator(LIST3_TAB_TAG).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return layoutTab3;
}
});
tabHost.addTab(tab3);
layoutTab3.setVisibility(View.INVISIBLE);
...
}
}
MY R.layout.main:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="#+id/list1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
<ListView android:id="#+id/list2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
<RelativeLayout android:id="#+id/running_app_relative_layout"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:id="#+id/coco" android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="#+id/running_app_listview"
android:scrollbars="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="fill_vertical"
android:layout_alignParentTop="true"></ListView>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
I've figured out that when a custom ListView contains focusable elements, onListItemClick won't work (I think it's the expected behaviour). So I've just removed the focus from the custom view and it did the trick. In other words, I added the following commands to my view:
android:focusable="false"
android:focusableInTouchMode="false"
The full explanation is avaiable here: How to fire onListItemClick in Listactivity with buttons in list?

Categories

Resources