بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
ست نشدن آیتم ها در listView
سلام
سوال 1:من یک لیست ویو ایجاد کردم که با کلیک بر روی (button) آیتم جدیدی به لیست ویو اضافه می کند و وقتی دو آیتم یا بیشتر می سازم و وقتی رو آیتم کلیک می کنم و به صفحه تغییرات می روم و اطلاعات رل set می کنم فقط آیتم اول لیست ویو تغییر میکند و آیتم های دیگر بدون تغییر می مانند(بر روی آیتمی غیر از آیتم اول کلیک شده) همچنین هنگام رفتن به صفحه تغییرات ، مقادیر آیتم اول را نشان می دهد
سوال 2 : چه طور می توانم مقدار پیش فرض زیر را به زمان حال تغییر بدم؟
TimeOicker
DatePicker
سوال3: چه طور می تونم در قسمت متد onActivityResult در کلاس ActivityEdit نام مخاطب را نیز در متغیری ذخیره کنم؟
0
0
کسی نیست جواب منو بده؟ (11 سال پیش)
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
mosbai
11 سال پیش
0
0
اینم از کدها
ActivityMain
public class ActivityMain extends Activity {
public ArrayAdapter adapter;
//public ListView lstcontent;
@Override
protected void onResume() {
super.onResume();
G.currentActivity = this;
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lstcontent = (ListView) findViewById(R.id.lstcontent);
adapter = new AdapterSms(G.smses);
lstcontent.setAdapter(adapter);
Button btnnew = (Button) findViewById(R.id.btnnew);
btnnew.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(G.currentActivity, ActivityEdit.class);
G.currentActivity.startActivity(intent);
StructSms sms = new StructSms();
sms.contact = "contact";
sms.contactNumber = "Contact Number";
sms.massage = "Massage";
sms.sendHour = "hh";
sms.sendMin = "min";
sms.sendDay = "dd";
sms.sendMonth = "mm";
sms.sendYear = "yy";
Toast.makeText(ActivityMain.this, "New Massage was created", Toast.LENGTH_SHORT).show();
G.smses.add(sms);
}
});
adapter.notifyDataSetChanged();
}
}
کلاس ActivityEdit
public class ActivityEdit extends Activity {
static final int PICK_CONTACT_REQUEST = 1;
public EditText edtcontactnumber;
@Override
protected void onResume() {
G.currentActivity = this;
super.onResume();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
edtcontactnumber = (EditText) findViewById(R.id.edtcontactnumber);
final EditText edtmassage = (EditText) findViewById(R.id.edtmassage);
Button btngetcontact = (Button) findViewById(R.id.btngetcontact);
Button btnfinish = (Button) findViewById(R.id.btnfinish);
Button btnsetdate = (Button) findViewById(R.id.btnsetdate);
Button btnsettime = (Button) findViewById(R.id.btnsettime);
final TextView txtmm = (TextView) findViewById(R.id.txtmm);
final TextView txtdd = (TextView) findViewById(R.id.txtdd);
final TextView txtyy = (TextView) findViewById(R.id.txtyy);
final TextView txthourr = (TextView) findViewById(R.id.txthourr);
final TextView txtminn = (TextView) findViewById(R.id.txtminn);
Bundle extras = getIntent().getExtras();
int position = 0;
if (extras != null) {
extras.getInt("POSITION");
}
final StructSms sms = G.smses.get(position);
edtcontactnumber.setText(sms.contactNumber);
edtmassage.setText(sms.massage);
txtmm.setText(sms.sendMonth);
txtdd.setText(sms.sendDay);
txtyy.setText(sms.sendYear);
txthourr.setText(sms.sendHour);
txtminn.setText(sms.sendMin);
btnfinish.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
sms.contactNumber = edtcontactnumber.getText().toString();
sms.massage = edtmassage.getText().toString();
sms.sendHour = txthourr.getText().toString();
sms.sendMin = txtminn.getText().toString();
sms.sendMonth = txtmm.getText().toString();
sms.sendDay = txtdd.getText().toString();
sms.sendYear = txtyy.getText().toString();
Toast.makeText(ActivityEdit.this, "Information have been changed", Toast.LENGTH_SHORT).show();
finish();
}
});
btngetcontact.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
pickContact();
}
});
btnsettime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//timePickerDialog();
OnTimeSetListener timeListener = new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
Toast.makeText(G.context, "Time Is Set", Toast.LENGTH_SHORT).show();
String seth = "";
String setm = "";
if (hour < 10) {
seth = "0";
}
if (minute < 10) {
setm = "0";
}
txthourr.setText(seth + String.valueOf(hour));
txtminn.setText(setm + String.valueOf(minute));
}
};
TimePickerDialog dialog = new TimePickerDialog(ActivityEdit.this, timeListener, 12, 59, true);
dialog.show();
}
});
btnsetdate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//datePickerDialog();
OnDateSetListener dateListener = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
Toast.makeText(G.context, "Time Is Set", Toast.LENGTH_SHORT).show();
String setm = "";
String setd = "";
if (month < 10) {
setm = "0";
}
if (day < 10) {
setd = "0";
}
txtmm.setText(setm + String.valueOf(month));
txtdd.setText(setd + String.valueOf(day));
txtyy.setText(String.valueOf(year));
}
};
DatePickerDialog dialog = new DatePickerDialog(ActivityEdit.this, dateListener, 2014, 05, 05);
dialog.show();
}
});
}
/*private void timePickerDialog() {
OnTimeSetListener timeListener = new OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
Toast.makeText(G.context, "Time Is Set", Toast.LENGTH_SHORT).show();
String seth = "";
String setm = "";
if (hour < 10) {
seth = "0";
}
if (minute < 10) {
setm = "0";
}
txthourr.setText(seth + String.valueOf(hour));
txtminn.setText(setm + String.valueOf(minute));
}
};
TimePickerDialog dialog = new TimePickerDialog(ActivityEdit.this, timeListener, 12, 59, true);
dialog.show();
};*/
/*private void datePickerDialog() {
OnDateSetListener dateListener = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
Toast.makeText(G.context, "Time Is Set", Toast.LENGTH_SHORT).show();
String setm = "";
String setd = "";
if (month < 10) {
setm = "0";
}
if (day < 10) {
setd = "0";
}
txtmm.setText(setm + String.valueOf(month));
txtdd.setText(setd + String.valueOf(day));
txtyy.setText(String.valueOf(year));
}
};
DatePickerDialog dialog = new DatePickerDialog(ActivityEdit.this, dateListener, 2014, 05, 05);
dialog.show();
};*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request it is that we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
// We only need the NUMBER column, because there will be only one row in the result
String[] projection = { Phone.NUMBER };
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
// Do something with the phone number...
Toast.makeText(G.context, "number is :" + number, Toast.LENGTH_SHORT).show();
edtcontactnumber.setText(number);
}
}
}
private void pickContact() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
}
کلاس AdapterSms
public class AdapterSms extends ArrayAdapter {
public AdapterSms(ArrayList array) {
super(G.context, R.layout.adapter_sms, array);
}
private static class ViewHolder {
public TextView txtcontact;
public TextView txtcontactnumber;
public TextView txtmassage;
public TextView txtyear;
public TextView txtmonth;
public TextView txtday;
public TextView txthour;
public TextView txtmin;
public ImageView imgdelete;
public ViewGroup layoutRoot;
public ViewHolder(View view) {
txtcontact = (TextView) view.findViewById(R.id.txtcontact);
txtcontactnumber = (TextView) view.findViewById(R.id.txtcontactnumber);
txtmassage = (TextView) view.findViewById(R.id.txtmassage);
txtyear = (TextView) view.findViewById(R.id.txtyear);
txtmonth = (TextView) view.findViewById(R.id.txtmonth);
txtday = (TextView) view.findViewById(R.id.txtday);
txthour = (TextView) view.findViewById(R.id.txthour);
txtmin = (TextView) view.findViewById(R.id.txtmin);
imgdelete = (ImageView) view.findViewById(R.id.imgdelete);
layoutRoot = (ViewGroup) view.findViewById(R.id.layoutRoot);
}
public void fill(final ArrayAdapter adapter, final StructSms item, final int position) {
txtcontact.setText(item.contact);
txtcontactnumber.setText(item.contactNumber);
txtmassage.setText(item.massage);
txtyear.setText(item.sendYear);
txtmonth.setText(item.sendMonth);
txtday.setText(item.sendDay);
txthour.setText(item.sendHour);
txtmin.setText(item.sendMin);
imgdelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/*ProgressDialog dialog = new ProgressDialog(G.context);
dialog.setTitle("Warnning");
dialog.setMessage("Are You sure?");
dialog.setButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
adapter.remove(item);
Toast.makeText(G.context, "the massage Delete", Toast.LENGTH_SHORT).show();
}
});
dialog.show();*/
Toast.makeText(G.context, "the massage Delete", Toast.LENGTH_SHORT).show();
adapter.remove(item);
}
});
layoutRoot.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(G.currentActivity, ActivityEdit.class);
intent.putExtra("POSITION", position);
G.currentActivity.startActivity(intent);
}
});
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
StructSms item = getItem(position);
if (convertView == null) {
convertView = G.inflater.inflate(R.layout.adapter_sms, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.fill(this, item, position);
return convertView;
}
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .