item را از لیست ویو پر نکن یه ارایه بگیر توی کلاس G تمام آیتم های لیست ویو را (ایتم های کلاسشو) بریز توی آرایه و فقط از position لیست ویو برای خوندن خونه ارایه استفاده کن بریز توی آیتم
بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
فرگمنت دیالوگ (حل شد)
مدیریت گفتگو
آخرین تغییر: 10 سال پیش
سلام : چطور میشه در یه فرگمنت دیالوگی که هستیم بتونیم دوباره reload کنیم ؟
فقط می دونم قبلش بایستی کنسلش کرد.
getDialog().cancel();
پاسخها 3
این کدهای من در فرگمنت دیالوگ !
adapter = new AdapterFragmentHelp(getActivity(), G.help);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
lHelp.setVisibility(View.GONE);
lListView.setVisibility(View.GONE);
finish.setVisibility(View.GONE);
item = (StructFragmentHelp) list.getItemAtPosition(position);
doProcess();
lDescHelp.setVisibility(View.VISIBLE);
lBack.setVisibility(View.VISIBLE);
}
});
finish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
getDialog().cancel();
}
});
lBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lDescHelp.setVisibility(View.GONE);
lBack.setVisibility(View.GONE);
lHelp.setVisibility(View.VISIBLE);
lListView.setVisibility(View.VISIBLE);
finish.setVisibility(View.VISIBLE);
}
});
return root;
}
@Override
public void onStart() {
super.onStart();
TextView textView = (TextView) this.getDialog().findViewById(android.R.id.title);
if (textView != null) {
textView.setGravity(Gravity.CENTER);
textView.setTextSize(16);
}
}
//Read Data
public void lData() {
String url = "http://192.168.1.1/help_android.php?action=read";
String result = Webservice.readUrl(url, null);
if (result != null) {
try {
G.help.clear();
JSONArray tasks = new JSONArray(result);
for (int i = 0; i < tasks.length(); i++) {
JSONObject object = tasks.getJSONObject(i);
StructFragmentHelp task = new StructFragmentHelp();
task.id = object.getInt("id");
task.title = object.getString("title");
task.desc = object.getString("desc");
task.image = object.getString("image");
G.help.add(task);
}
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
public void doProcess() {
String content = item.desc;
Pattern pattern = Pattern.compile("\\[image:'(.*?)'\\]");
Matcher matcher = pattern.matcher(content);
int lastIndex = 0;
if (matcher.find()) {
String newContent = content.substring(lastIndex, matcher.start(1)).replace("[image:'", "").replace("']", "");
addTextView(newContent);
String imageName = content.substring(matcher.start(1), matcher.end(1));
addImageView(imageName);
lastIndex = matcher.end(1);
}
String newContent = content.substring(lastIndex, content.length()).replace("[image:'", "").replace("']", "");
addTextView(newContent);
}
private void addImageView(String imageName) {
ImageView imageView = new ImageView(getActivity());
if (!item.image.equals("")) {
Picasso.with(getActivity())
.load(item.image)
.placeholder(R.drawable.picasso_smile)
.error(R.drawable.picasso_close)
.into(imageView);
}
layoutRoot.addView(imageView);
}
private void addTextView(String text) {
TextView textView = new TextView(getActivity());
textView.setText(text);
textView.setTextSize(12);
textView.setTextColor(Color.BLUE);
textView.setTypeface(G.typeface);
layoutRoot.addView(textView);
}
class HelpAsync extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
lData();
return null;
}
@Override
protected void onPreExecute() {
showProgressBar_page();
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
hideProgressBar_page();
lHelp.setVisibility(View.VISIBLE);
lListView.setVisibility(View.VISIBLE);
finish.setVisibility(View.VISIBLE);
list.setAdapter(adapter);
}
}
نظرات
احمد جان میشه با کد توضیح بدی ؟ الان گیج شدم ! :(
روی پروژه note برات مثال میزنم: این کلاسمنونه
public class StructTask {
public long task_id;
public String task_title;
public String task_desc;
public boolean task_done;
}
حالا توی کلاس G یه ارایه میسازی: کدهای اضافیش را گذاشتم که بدونی کجا تعریف کردم
public class G extends Application {
public static Context context;
public static LayoutInflater inflater;
public static Activity currentActivity;
public static ArrayList<StructTask> tasks = new ArrayList<StructTask>();
}
حالا وقتی اطلاعات را گرفتی اول ارایه را پر می کنی بعد ارایه را پاس میدی به ادابتر لیست ویو:
adabter = new AdapterNote(G.tasks); lstnotes.setAdapter(adabter);
حالا توی کلیک لیست می تونی اینتوری بنویسی:
lstnotes.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
StructTask item = G.tasks.get(position);
btnaddnorte.setText(item.task_title);
// TODO Auto-generated method stub
}
});
نظرات
احمد جان من که همه اینا رو ساختم . اگه تو کدهای من نگاه کنی همش هست !! :(
قسمت کلیک لیستت را مقایسه کن
اون رو هم مثل کد شما گذاشتم نشد. وقتی doProcess(); بردارم از کلیک لیست درسته متن . تکرار نمیشه ولی اون رو میزارم که بتونم بین متن عکس هم استفاده کنم این مشکل پیش میاد .
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات