Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I faced the problem of storing value of datepicker in the listview but resolved it.This is the code for it.Hope it helps.</p> <pre><code>import java.util.ArrayList; import java.util.Calendar; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.DatePicker; import android.widget.ListView; import android.widget.TextView; public class DAteDemo extends Activity{ private ListView listViewScore = null; private ListViewAdapter listViewAdapter = null; static final int DATE_DIALOG_ID = 0; private int mYear; private int mMonth; private int mDay; int globalPosition; //used for storing the position of textview clicked for setting the date ArrayList&lt;String&gt; mfddateList = null; int viewlength = 30; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); listViewScore=(ListView)findViewById(R.id.listViewScore); mfddateList = new ArrayList&lt;String&gt;(); for(int i=0;i&lt;30;i++){ mfddateList.add(""); } final Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); listViewAdapter = new ListViewAdapter(); listViewScore.setAdapter(listViewAdapter); } class ListViewAdapter extends BaseAdapter{ @Override public int getCount() { return viewlength; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View view, ViewGroup parent) { // TODO Auto-generated method stub final ViewHolder viewHolder ; View rowView=view; if(rowView==null){ LayoutInflater layoutinflate =LayoutInflater.from(DAteDemo.this); rowView=layoutinflate.inflate(R.layout.listviewnewtext, parent, false); viewHolder = new ViewHolder(); viewHolder.et_Sort_Order = (TextView)rowView.findViewById(R.id.et_Sort_Order); //Setting listen to the text box viewHolder.et_Sort_Order.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub showDialog(DATE_DIALOG_ID); globalPosition = viewHolder.ref; // this is used to update the date Log.i("Log","date:-- "+viewHolder.ref); } }); rowView.setTag(viewHolder); }else{ viewHolder = (ViewHolder) rowView.getTag(); } viewHolder.ref = position; viewHolder.et_Sort_Order.setText(mfddateList.get(position)); return rowView; } }//class ends class ViewHolder{ TextView et_Sort_Order; int ref; } // the callback received when the user "sets" the date in the dialog public DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; String date = (mMonth + 1)+"/"+mYear; mfddateList.set(globalPosition,date); Log.i("Log", "i m in dateset "+globalPosition); listViewAdapter.notifyDataSetChanged(); //for updating the date change } }; @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(DAteDemo.this,mDateSetListener,mYear, mMonth,mDay ); } return null; } }//ActivityEnds **main.xml** &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ListView android:layout_width="match_parent" android:id="@+id/listViewScore" android:cacheColorHint="#00000000" android:layout_height="match_parent" android:layout_weight="1.00" android:divider="#C0C0C0" android:layout_below="@+id/layout" android:dividerHeight="2dip" android:background="@android:color/white" /&gt; </code></pre> <p></p> <pre><code>**listviewnewtext.xml** &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="2dip" android:paddingBottom="0dip" &gt; &lt;TextView android:textColor="@android:color/black" android:layout_height="wrap_content" android:layout_width="80dip" android:focusable="false" android:id="@+id/et_Sort_Order" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload