This question already has answers here:
How to customized the ListView height in android?
(4 answers)
Closed 5 years ago.
I am a beginner to android. I want to display a customized list view which contains a number. I customized my List item height size(android:layout_height="50dp"). But when I run the app it display the size largely which am not given. I don't know how to fix this problem. Could anyone help me?
activity_topic_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.yuvi.secrectsforhappylife.TopicList">
<ListView
android:id="#+id/topiclist"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
titledesign.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="50dp"
android:background="#drawable/storylist">
<TextView
android:id="#+id/topictitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/title"
android:textSize="25sp"
android:textStyle="bold"
android:textColor="#android:color/background_light" />
</RelativeLayout>
TopicList.java
public class TopicList extends AppCompatActivity {
String topic\[\]={"one","two","three","four","five","six","seven","eight","nine","ten"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_topic_list);
ListView listView=(ListView)findViewById(R.id.topiclist);
CustomAdapter customAdapter=new CustomAdapter();
listView.setAdapter(customAdapter);
}
class CustomAdapter extends BaseAdapter
{
#Override
public int getCount() {
return topic.length;
}
#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) {
convertView=getLayoutInflater().inflate(R.layout.titledesign,null);
TextView title=(TextView)convertView.findViewById(R.id.topictitle);
title.setText(topic\[position\]);
return convertView;
}
}
}
Try below code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/storylist">
and make changes in your listview also like below
<ListView
android:id="#+id/topiclist"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Related
HI so im making this File manager app for my portfolio , im fairly now to android programming , im trying to display files and folder via Recyclerview . but for some DAMN reason it is not showing list of items ..like fragment is switching default layout to fragment containing recyclerview but that recyclerview is not displaying the item-layout. PLEASE HELP
thanks a LOT in advance (this issue is driving me insane)
EDIT: there is an error saying "no adapter attached,skipping layout", and YES i have seen all stack overflow threads regarding it .. my case is a bit different
here is the MainActivity
public class FilesDisplayActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_files_display);
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
ItemFragment fragment = new ItemFragment();
transaction.replace(R.id.frame_layout, fragment);
transaction.commit();
}
}
}
and here the Fragment Replacing its Layout
public class FilesDisplayFragment extends Fragment {
RecyclerView recyclerView;
ArrayList<DataModel> dataHolder;
int fileFoundCount;
File dir;
File[] files;
public FilesDisplayFragment() {
}
public static FilesDisplayFragment newInstance() {
FilesDisplayFragment fragment = new FilesDisplayFragment();
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String rootpath=String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));
dir = new File(rootpath);
files= dir.listFiles();
if(files.length>0){
Log.i("FILESNOTNULL","TRUE");
}
dataHolder=new ArrayList<>();
for(int i =0;i<fileFoundCount;i++){
dataHolder.add(new DataModel(R.drawable.folder,files[i].getAbsolutePath(),1,1,"0/0/0"));
//this is just a test data
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_files_display, container, false);
recyclerView=(RecyclerView)view.findViewById(R.id.files_rec_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
MyItemRecyclerViewListAdapter adapter = new MyItemRecyclerViewListAdapter(dataHolder);
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
return view;
}
}
and here is the adapter
public class FilesDisplayAdapter extends RecyclerView.Adapter<FilesDisplayAdapter.myViewHolder>{
ArrayList<DataModel> dataholder;
public FilesDisplayAdapter(ArrayList<DataModel> arrayList) {
this.dataholder = arrayList;
}
#NonNull
#Override
public myViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.files_or_folders,parent,false);
return new myViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull myViewHolder holder, int position) {
holder.img.setImageResource(dataholder.get(position).getImg());
holder.filename.setText(String.valueOf(dataholder.get(position).getFileName()));
holder.filesize.setText(String.valueOf(dataholder.get(position).getFilesize()));
holder.subitems.setText(String.valueOf(dataholder.get(position).getNoOfItems()));
holder.dateCreated.setText(String.valueOf(dataholder.get(position).getDateCreated()));
Log.i("DEBUG", String.valueOf(holder.filename.getText()));
Log.i("Message",dataholder.get(position).getFileName());
}
#Override
public int getItemCount() {
Log.i("DATASIZE",String.valueOf(dataholder.size()));
return dataholder.size();
}
class myViewHolder extends RecyclerView.ViewHolder{
ImageView img;
TextView filename,filesize,subitems,dateCreated;
public myViewHolder(#NonNull View itemView) {
super(itemView);
img=itemView.findViewById(R.id.fof_imagview);
filename=itemView.findViewById(R.id.file_name_view);
filesize=itemView.findViewById(R.id.fof_size);
subitems=itemView.findViewById(R.id.fof_no_of_items);
dateCreated=itemView.findViewById(R.id.fof_date_created);
}
}
}
xml of original activity
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/frame_layout"
tools:context=".FilesDisplayActivity">
</FrameLayout>
xml of fragment
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".ui.main.FilesDisplayFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/files_rec_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:background="#EAE6E6" />
</FrameLayout>
xml of item view holder
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<androidx.cardview.widget.CardView
android:id="#+id/CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/fof_imagview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5sp"
android:src="#drawable/folder">
</androidx.appcompat.widget.AppCompatImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:orientation="horizontal">
<TextView
android:id="#+id/file_name_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="30sp"
android:text="File Name"/>
<TextView
android:id="#+id/fof_size"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="#+id/file_name"
android:layout_marginStart="30sp"
android:gravity="center"
android:text="Size" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5sp"
android:orientation="horizontal">
<TextView
android:id="#+id/fof_no_of_items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20sp"
android:text="no Of items"/>
<TextView
android:id="#+id/fof_date_created"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20sp"
android:text="Date Created"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
LOG file exceeding the character capacity .all i could find there is "no adapter attached , skipping layout " ..else seemed fine
I am a beginner to android. I want to display a customized list view which contains a number. I customized my ListView size(android:layout_height="50dp"). But when I run the app it display the size largely which am not given. I don't know how to fix this problem. Please anyone help me.
activity_topic_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.yuvi.secrectsforhappylife.TopicList">
<ListView
android:id="#+id/topiclist"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
titledesign.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="#drawable/storylist">
<TextView
android:id="#+id/topictitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/title"
android:textSize="12pt"
android:textStyle="bold"
android:textColor="#android:color/background_light" />
</RelativeLayout>
TopicList.java
public class TopicList extends AppCompatActivity {
String topic[]={"one","two","three","four","five","six","seven","eight","nine","ten"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_topic_list);
ListView listView=(ListView)findViewById(R.id.topiclist);
CustomAdapter customAdapter=new CustomAdapter();
listView.setAdapter(customAdapter);
}
class CustomAdapter extends BaseAdapter
{
#Override
public int getCount() {
return topic.length;
}
#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) {
convertView=getLayoutInflater().inflate(R.layout.titledesign,null);
TextView title=(TextView)convertView.findViewById(R.id.topictitle);
title.setText(topic[position]);
return convertView;
}
}
}
I want to fix the list cell height
FYI
You want to add HEIGHT for each Cell
Then
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/storylist">
<TextView
android:id="#+id/topictitle"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/title"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#android:color/background_light" />
</RelativeLayout>
Note
Use TextView Size unit sp instead of pt .
Try below changes on your parent layout on titledesign.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/storylist">
and if you want that your list capture full width of device screen make change on layout_width like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/storylist">
This should help you out..
ListAdapter listadp = lv_ancillaryservice.getAdapter();
if (listadp != null) {
int totalHeight = 0;
for (int i = 0; i < listadp.getCount(); i++) {
View listItem = listadp.getView(i, null, lv_ancillaryservice);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = lv_ancillaryservice.getLayoutParams();
params.height = totalHeight + (lv_ancillaryservice.getDividerHeight() * (listadp.getCount() - 1));
lv_ancillaryservice.setLayoutParams(params);
lv_ancillaryservice.requestLayout();
Create the List view as
activity_word.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="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:padding="5dp"
android:textSize="25dp"
android:gravity="center_horizontal|center_vertical"
android:text="Text"
android:id="#+id/text_list_view" />
</LinearLayout>
create another xml file and create a text view in it
listitem.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">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="#+id/listView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
in the Toplist java class add this as setContentView
setContentView(R.layout.activity_word);
Whenever I use a base adapter to add a view to a gallery it causes the EditText from within the view to not allow text input, it focuses and the keyboard appears but when I enter text it doesn't appear. The EditText type is numberDecimal.
I have tried setting the content view of MainActivity to ap_overview_add and the EditText works fine.
activity_main.xml
<?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.mwapps.baseadaptertest.MainActivity">
<Gallery
android:id="#+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:padding="20dp" />
</RelativeLayout>
ap_overview_add.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="match_parent"
android:orientation="vertical"
android:id="#+id/ap_overview_add_LL"
android:gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/ap_et_add"
android:inputType="numberDecimal"
android:padding="10dp"
android:backgroundTint="#color/abc_secondary_text_material_light"
android:imeOptions="actionSend"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:layout_weight=".75"
android:clickable="true"
android:text="300"
android:focusable="true"
android:focusableInTouchMode="true" />
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
Gallery gallery;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new GalleryImageAdapter(this));
}
}
GalleryImageAdapter.java
public class GalleryImageAdapter extends BaseAdapter {
Context mContext;
LayoutInflater inflater;
public GalleryImageAdapter(Context context)
{
mContext = context;
}
public int getCount() {
return 1;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
// Override this method according to your need
public View getView(int index, View view, ViewGroup viewGroup)
{
// TODO Auto-generated method stub
inflater = LayoutInflater.from(mContext);
View tab;
tab = inflater.inflate(R.layout.ap_overview_add, viewGroup, false);
return tab;
}
}
I've looked at other questions similar and nothing has worked, including trying to change the softinput mode, what is causing the text to not be entered?
Edit: If the inputType is changed to text it allows input
Edit 2: If the inputtype is set to numberDecimal, numbers cannot be entered but things like commas can be, so it looks like it's not accepting numbers
You can use ViewPager instead of Gallery as suggested in developer.android.com/reference/android/widget/Gallery.html
to make it work
I know that there has been simialr questions but I can't make it work even though I look at those. The error message is:
java.lang.RuntimeException: Your content must have a ListView whose id
attribute is 'android.R.id.list'
. I have tried to change the id to list. In another. This what the code looks like:
public class committeeFragment extends SherlockListFragment {
private CommitteeAdapter adapter;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new CommitteeAdapter(getActivity().getApplicationContext());
setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.fragment_committee, container, false);
}
public void
refreshList() {
adapter.updateDataSet();
adapter.notifyDataSetChanged();
}
}
It's using the following adapter:
public class CommitteeAdapter extends BaseAdapter {
private
ArrayList<StudentCommittee> committeeList;
private Context context;
public CommitteeAdapter(Context context) {
this.context = context;
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
public void updateDataSet() {
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
StudentCommittee committee = committeeList.get(position);
View v = vi.inflate(R.layout.list_item_committee, null);
TextView sectionName = (TextView) v.findViewById(R.id.committee_namn);
sectionName.setText(committee.getName());
return v;
}
#Override
public int getCount() {
return committeeList.size();
}
#Override
public StudentCommittee getItem(int position) {
return committeeList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
}
Here is the xml-file that specifies the list(fragment_committee):
<?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"
android:tag="#string/tag_fragment_committee"
android:background="#color/white" >
<TextView
style="#style/AppsolutText.Headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Festerier" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#drawable/divider_sliding_menu_item"/>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
style="#style/AppsolutText.Normal"
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Uppdatera för att se en lista över festerier och fadderier. Kräver internetanslutning."/>
</LinearLayout>
Here is the xml for the list item:
<?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="horizontal" >
<ImageView
android:id="#+id/committee_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
<TextView
android:id="#+id/committee_namn"
style="#style/AppsolutText.ListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I hope that you can figure out what's wrong. I have another listview that has the same id (list) in another xml-file within the project. I don't know if that's a problem. Please help me solve the problem.
The problem is here :
android:id="#+id/list"
you are adding a new id for your ListView but ListFragment needs a default Android ListView Id
change your ListView Id to :
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Change your ListView in XML to have the following id:
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
It's a requirement of using ListFragment/SherlockListFragment
http://developer.android.com/reference/android/app/ListFragment.html
ListFragment has a default layout that consists of a single list view. However, if you desire, you can customize the fragment layout by returning your own view hierarchy from onCreateView(LayoutInflater, ViewGroup, Bundle). To do this, your view hierarchy must contain a ListView object with the id "#android:id/list" (or list if it's in code)
You can try to clean your project. If any xml releted error have , you can find it. Then you can change your list id . Find the list id are exist into your gen folder R.java class.
I decided to stop using actionbarsherlock and use the support libraries instead to get action bar in Android 2.1 and above. After doing this, i got the "java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'". What i did to remedy this problem was
to read this http://developer.android.com/reference/android/app/ListFragment.html#q=fragment
then change my fragment layout file from
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context=".ItemDetailFragment" />
to
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
tools:context=".ItemDetailFragment">
<ListView android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:text="No data"/>
... and voila, the RunTimeException with missing android.R.id.list was gone! Of course, i need to edit my new layout and fix it properly, but the key issue here was that i had overridden the fragment layout in its onCreateView method. ActionBarSherlock DID NOT have a problem with this, but with the Android support library, if u do this, you MUST have a ListView in your XML Layout, with the android:id="#id/android:list" as stated in the info linked to above.
Hope this helps (coming from a total newb in Android app dev)!
This is probably a stupid question.
I know I can wrap a ListView in ViewFlipper, but can we wrap individual ListView Items in a ViewFlipper? For instance, the latest Twitter app uses a ListView to display Tweets. It also allows you to set settings on individual items by sliding the tweet out of the way exposing the setting option icons below. Is this a custom implementation or do we have the ability to create something similar using ListView and ViewFlipper? Thanks, any advice is appreciated!
I've spent some time on this and got the ListView to display additional content via the ViewFlipper. However, the view only seems to "flip" on the last item in the ListView. How do I get each item to flip when clicked? Here's some code:
row.xml
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/flipper" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="#+id/toptext" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"
android:gravity="center_vertical" />
<TextView android:id="#+id/bottomtext" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"
android:gravity="center_vertical" />
</ViewFlipper>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
ListActivityView.java - extends ListActivity
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// doesn't matter which line is clicked
// only the last item in the ListView displays the bottomText
viewFlipper.showNext();
}
ListingAdapter.java - extends ArrayAdapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
viewFlipper = (ViewFlipper) v.findViewById(R.id.flipper);
}
If I am getting your question correct - you can use ViewFlipper inside a layout that defines a row in your list and init it the way you like when rendering corresponding view
Below code helps you achieve a requirement for having a view flipper in list view with invidual row flipping
## xml file ##
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/regularLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/activity_horizontal_margin">
<ViewFlipper
android:id="#+id/row_item_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:id="#+id/list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Regular Layout"
android:textSize="28sp" />
<Button
android:text="Flip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/front_button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:id="#+id/backTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flip row done"
android:textSize="18sp" />
<Button
android:text="Flip back"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/back_button" />
</LinearLayout>
</ViewFlipper>
</LinearLayout>
----------
## Java code ##
#Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_item, parent, false);
return new ItemViewHolder(itemView);
}
#Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
final CustomItem data = dataList.get(position);
holder.regularLayout.setVisibility(View.VISIBLE);
holder.swipeLayout.setVisibility(View.GONE);
holder.listItem.setText(data.dataItemValue );
holder.backTextView.setText(data.dataItemValue + " position : "+ position);
holder.viewFlipper.setFlipInterval(0);
holder.viewFlipper.setInAnimation(null);
holder.viewFlipper.setOutAnimation(null);
if(holder.viewFlipper.getDisplayedChild()==0 && data.isFlipON){
holder.viewFlipper.setDisplayedChild(1);
} else if(holder.viewFlipper.getDisplayedChild()==1 && !data.isFlipON){
holder.viewFlipper.setDisplayedChild(0);
}else if(data.isFlipON){
holder.viewFlipper.setDisplayedChild(1);
}else{
holder.viewFlipper.setDisplayedChild(0);
}
holder.frontButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AnimationFactory.flipTransition(holder.viewFlipper, AnimationFactory.FlipDirection.LEFT_RIGHT);
data.isFlipON = true;
}
});
holder.backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
data.isFlipON = false;
AnimationFactory.flipTransition(holder.viewFlipper, AnimationFactory.FlipDirection.LEFT_RIGHT);
}
});
}