how to use getListView() in Activity?

Whenever you use Activity you set your_layout.xml as your Activity‘s ContentView. So the ListView should b in your_layout.xml. That ListView should have an id attribute defined in xml file say: (android:id=”@+id/list”). You get your ListView object some thing like this way: setContentView(R.layout.your_layout); ListView list = (ListView)findViewById(R.id.list); list.addFooterView(view); And when you use ListActivity you get your … Read more

Android: Adding static header to the top of a ListActivity

findViewById() only works to find subviews of the object View. It will not work on a layout id. You’ll have to use layout inflater to convert the xml to it’s corresponding View components. Something like this: ListView lv = getListView(); LayoutInflater inflater = getLayoutInflater(); View header = inflater.inflate(R.layout.header, lv, false); lv.addHeaderView(header, null, false); I’m not … Read more

Duplicated entries in ListView

Try this: public View getView(int position, View convertView, ViewGroup parent) { if (null == convertView) { LinearLayout view = (LinearLayout) LinearLayout.inflate(this.context, R.layout.message, null); Log.d(“SeenDroid”, String.format(“Get view %d”, position)); TextView title = new TextView(view.getContext()); title.setText(this.items.get(position).getTitle()); view.addView(title); return view; } else { LinearLayout view = (LinearLayout) convertView; TextView title = (TextView) view.getChildAt(0); title.setText(this.items.get(position).getTitle()); return convertView; } } … Read more

Android Swipe on List

I had the same problem and I didn’t find my answer here. I wanted to detect a swipe action in ListView item and mark it as swiped, while continue to support OnItemClick and OnItemLongClick. Here is me solution: 1st The SwipeDetector class: import android.util.Log; import android.view.MotionEvent; import android.view.View; public class SwipeDetector implements View.OnTouchListener { public … Read more

How to implement RecyclerView with CardView rows in a Fragment with TabLayout

Here is a simple example using a TabLayout and a RecyclerView with a CardView in each row. First, MainActivity, which sets up the ViewPager and TabLayout: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Get the ViewPager and set it’s PagerAdapter so … Read more