Sammy
Sammy

Reputation: 181

Add bullet points between textview in horizontal listview

I have a horizontal listview of text. I want to add COLORED BULLET POINTS in between those texts. I used Gallery to display horizontal listview. The final view should be same as in the image. Also, how to get a divider like in the image between the Gallery and textview?

Activity

public class MainActivity extends Activity {
	
	 Gallery myHorizontalListView;
	 MyAdapter myAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		myHorizontalListView = (Gallery)findViewById(R.id.horizontallistview);
	     
	      myAdapter = new MyAdapter(this);
	      myHorizontalListView.setAdapter(myAdapter);
	     
	      myHorizontalListView.setOnItemClickListener(new OnItemClickListener(){
	 
	   @Override
	   public void onItemClick(AdapterView<?> parent, View view, int position,
	     long id) {
	    Toast.makeText(MainActivity.this, parent.getItemAtPosition(position).toString() + " Clicked", Toast.LENGTH_LONG).show();
	     
	   }});
	     
	  }
	 
	  public class MyAdapter extends BaseAdapter {
	    
	   Context context;
	    
	   String[] itemsArray = {
	     "SUN","MON", "TUS", "WED", "THU", "FRI", "SAT"};
	    
	   MyAdapter(Context c){
	    context = c;
	   }
	 
	  @Override
	  public int getCount() {
	   // TODO Auto-generated method stub
	   return itemsArray.length;
	  }
	 
	  @Override
	  public Object getItem(int position) {
	   // TODO Auto-generated method stub
	   return itemsArray[position];
	  }
	 
	  @Override
	  public long getItemId(int position) {
	   // TODO Auto-generated method stub
	   return position;
	  }
	 
	  @Override
	  public View getView(int position, View convertView, ViewGroup parent) {
	   // TODO Auto-generated method stub
	    
	   View rowView = LayoutInflater
	     .from(parent.getContext())
	     .inflate(R.layout.row, null);
	   TextView listTextView = (TextView)rowView.findViewById(R.id.itemtext);
	   listTextView.setText(itemsArray[position]);
	    
	   return rowView;
	  }
	   
	   
	  }
	}

I'm Trying to achieve like this

Upvotes: 0

Views: 684

Answers (1)

Amarjit
Amarjit

Reputation: 4357

Use drawableLeft property for adding bullets in textview

as for xml

android:drawableLeft="your_file"

also in your view first image has no bullet then in code put check that

if(position == 0)
listTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);

Upvotes: 1

Related Questions