رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

پست های پیشنهاد شده

سلام :

من یه برنامه محتوایی دارم ولی وقتی محتویات دیتا بیسم زیاد میشه (در حال حاضر 2000 رکورد در چند جدول) در زمان نمایش در لیست ویو به سرعت نشون نمیده و یه تاخیر 2 ثانیه های داره . برای حل این مشکل چی پیشنهاد میدید؟

لینک ارسال
به اشتراک گذاری در سایت های دیگر

سلام

شما اگر لیست ویو رو سفارشی درست کنید ! که از نوع Baseadapter باشه و ویوهولدر داشته باشید ! با کندی برخورد نخواهید کرد.

لینک ارسال
به اشتراک گذاری در سایت های دیگر

سلام

شما اگر لیست ویو رو سفارشی درست کنید ! که از نوع Baseadapter باشه و ویوهولدر داشته باشید ! با کندی برخورد نخواهید کرد.

کد های که استفاده کردم 

package com.AppLike.office_help_me;


import android.app.ListActivity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


public class list_story_mail extends ListActivity {



private database db;
private String[] Name;
private String[] Name_main;
private String[] Tedad;
private String[] Fav;

private String sea;


@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.list_story_mail);


	android.app.ActionBar mActionBar = getActionBar();
	mActionBar.setDisplayShowHomeEnabled(false);
	mActionBar.setDisplayShowTitleEnabled(false);
	LayoutInflater mInflater = LayoutInflater.from(this);
	View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);



	ImageButton imageButton = (ImageButton) mCustomView
			.findViewById(R.id.imageButton);
			imageButton.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {

			           Intent i = new Intent(list_story_mail.this,menu.class);

			           startActivity(i);
			           overridePendingTransition(R.anim.out, R.anim.in);
				}
			});


			ImageButton btn_share = (ImageButton) mCustomView
					.findViewById(R.id.btn_share);
					btn_share.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View view) {
	                    Intent s = new Intent(list_story_mail.this,MainActivity.class);
	                    startActivity(s);
	                    overridePendingTransition(R.anim.out, R.anim.in);
					}
					});

			//فعال کردن اکشن بار سفارشی
			mActionBar.setCustomView(mCustomView);
			mActionBar.setDisplayShowCustomEnabled(true);

	db=new database(this);

	Bundle ex=getIntent().getExtras();
	sea=ex.getString("sea");


	refresh();
	setListAdapter(new AAA());
	TextView text_action = (TextView) mCustomView.findViewById(R.id.action_text);
	text_action.setText(sea);
	Typeface face = Typeface.createFromAsset(getAssets(),
            "font/koodak.ttf");

	text_action.setTypeface(face);

}


class AAA extends ArrayAdapter{


	public AAA(){
		super(list_story_mail.this,R.layout.row_story_mail,Name);
	}



	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {


		LayoutInflater in=getLayoutInflater();
		View row=in.inflate(R.layout.row_story_mail, parent,false);

		final TextView name=(TextView) row.findViewById(R.id.row_story_name);
		final TextView tedad=(TextView) row.findViewById(R.id.row_story_tedad);
		final ImageView fav =(ImageView)row.findViewById(R.id.fav);
		final ImageView copy =(ImageView)row.findViewById(R.id.copy);
		Button btn_share = (Button)row.findViewById(R.id.share);

		TextView count_row = (TextView)row.findViewById(R.id.count_row);

		for(int i = 0 ; i<=position;i+=1){
			count_row.setText(String.valueOf(position+1));
		}

		Typeface face = Typeface.createFromAsset(getAssets(),
	            "font/koodak.ttf");
		count_row.setTypeface(face);

		btn_share.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {


				Intent sharing = new Intent(android.content.Intent.ACTION_SEND);
		        sharing.setType("text/plain");
		        sharing.putExtra(android.content.Intent.EXTRA_TEXT,name.getText().toString() +" : \n "+ 
		        tedad.getText().toString()+"\n  \n ارسال شده از اپلیکیشن کمک یار اداره ");
		        startActivity(Intent.createChooser(sharing, "اشتراک گذاری با"));




			}
		});



		copy.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				 ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
				 ClipData clip = ClipData.newPlainText("",name.getText().toString() +" : \n "+ 
					        tedad.getText().toString());
				 clipboard.setPrimaryClip(clip);
				 Toast toast_style = Toast.makeText(getApplicationContext(), "کپی شد",
				 Toast.LENGTH_LONG);

					View vieew = toast_style.getView();
					vieew.setBackgroundResource(R.drawable.toast_style);
	                toast_style.setView(vieew);
	                toast_style.show();

			}
		});
	  	if(Fav[position].equals("1")){
	  		fav.setImageResource(R.drawable.ic_favorite_white_48dp);
	  	}else{
	  		fav.setImageResource(R.drawable.ic_favorite_outline_white_48dp);
	  	}


	  	fav.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				db.open();
			  	if(Fav[position].equals("1")){


					db.fav_update("mail", sea, Name[position], "0");
					fav.setImageResource(R.drawable.ic_favorite_outline_white_48dp);
					Fav[position]="0";
					Toast toast_style =Toast.makeText(getApplicationContext(), "از لیست علاقه مندی های  بخش نامه ها حذف شد", Toast.LENGTH_SHORT);
					View vieew = toast_style.getView();
					vieew.setBackgroundResource(R.drawable.toast_style);
	                toast_style.setView(vieew);
	                toast_style.show();

			  	}else{

					db.fav_update("mail", sea, Name[position], "1");
					fav.setImageResource(R.drawable.ic_favorite_white_48dp);
					Fav[position]="1";
					Toast toast_style =	Toast.makeText(getApplicationContext(), "به لیست علاقه مندی های بخش نامه ها اضافه شد", Toast.LENGTH_SHORT);
					View vieew = toast_style.getView();
					vieew.setBackgroundResource(R.drawable.toast_style);
	                toast_style.setView(vieew);
	                toast_style.show();

			  	}
				db.close();
			}
		});


		name.setTypeface(MainActivity.font);
		name.setTextSize(MainActivity.size);


		tedad.setTypeface(MainActivity.font);
		tedad.setTextSize(MainActivity.size);
		tedad.setLineSpacing(MainActivity.space,1);


		name.setText(Name[position]);
		tedad.setText(Name_main[position]);



		if(MainActivity.mode.equals("day")){

			Resources res = getResources(); 
			Drawable dr = res.getDrawable(R.drawable.day);
			row.setBackgroundDrawable(dr);


			name.setTextColor(Color.parseColor("#575757"));
			tedad.setTextColor(Color.parseColor("#575757"));





		}else{

			Resources res = getResources(); 
			Drawable dr = res.getDrawable(R.drawable.night);
			row.setBackgroundDrawable(dr);

			name.setTextColor(Color.WHITE);
			tedad.setTextColor(Color.WHITE);


		}

		return (row);
	}


}



private void refresh(){

	db.open();
	int s=db.S2_count("mail", sea);

	Name=new String[s];
	Name_main=new String[s];
	Tedad=new String[s];
	Fav=new String[s];

	for(int i=0;i			
		Name[i]=db.Story2_display("mail", i, sea,1);
		Name_main[i]=db.Story2_display("mail", i, sea,2);
	//	Tedad[i]=db.Story2_display("content", i, sea, 0);
		Fav[i]=db.Story2_display("mail", i, sea, 6);

	}


	db.close();

}
public void onBackPressed() {
    super.onBackPressed();
    finish();
    overridePendingTransition(R.anim.out, R.anim.in);
}

}


اگر اینجوری نباید باشه

اگه میشه یه منبعی برای لودر معرفی کنید 

ممنون :)

لینک ارسال
به اشتراک گذاری در سایت های دیگر

سلام :

ممنون از جوابتون

اگه امکانش هست میشه  این کلاس رو اینجا قرار بدید و بگید که چطور در کدی که در بالا گذاشتم استفاده کنم.

لینک ارسال
به اشتراک گذاری در سایت های دیگر

کسی نیست جواب بده که چه جوری میتونم viewholder رو در کدی که قرار دادم استفاده کنم 

واقعا نیاز دارم به استفاده از  کلاس (viewholder)

لینک ارسال
به اشتراک گذاری در سایت های دیگر

این لیست ویویی که خودم استفاده میکنم  و تا حالا ندیدم کند بشه 

 اکتیوتی اصلی

public class ListViewActivity extends Activity {

   public ArrayAdapter          adapter;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       adapter = new AdapterNote(G.notes);
       ListView lst = (ListView) findViewById(R.id.lst);
       lst.setAdapter(adapter);
       for (int i = 0; i < 20; i++) {
           StruckNote note = new StruckNote();
           note.title = "title" + i;
           note.description = "description" + i;
           G.notes.add(note);
       }
       adapter.notifyDataSetChanged();
   }
}

کلاس AdapterNote

public class AdapterNote extends ArrayAdapter {

   public AdapterNote(ArrayList array) {
       super(G.context, R.layout.adapternote, array);

   }


   private static class ViewHolder {

       public ViewGroup Layout_Root;
       public TextView  txtTitle;
       public TextView  txtDesription;


       public ViewHolder(View view) {
           txtTitle = (TextView) view.findViewById(R.id.txtTitle);
           txtDesription = (TextView) view.findViewById(R.id.txtDesription);
           Layout_Root = (ViewGroup) view.findViewById(R.id.Layout_Root);
       }


       public void fill(ArrayAdapter adapter, final StruckNote item, int position) {
           txtTitle.setText(item.title);
           txtDesription.setText(item.description);
           Layout_Root.setOnClickListener(new OnClickListener() {

               @Override
               public void onClick(View arg0) {
                   Intent intent = new Intent(G.currentactivity, detail.class);
                   G.currentactivity.startActivity(intent);

               }
           });
       }
   }


   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder;
       StruckNote item = getItem(position);
       if (convertView == null) {
           convertView = G.in.inflate(R.layout.adapternote, parent, false);
           holder = new ViewHolder(convertView);
           convertView.setTag(holder);
       } else {
           holder = (ViewHolder) convertView.getTag();
       }
       holder.fill(this, item, position);
       return convertView;
   }
}

کلاس G

public class G extends Application {

   public static Context        context;
   public static LayoutInflater in;
   public static Activity       currentactivity;

   public static ArrayList notes = new ArrayList();

   @Override
   public void onCreate() {
       super.onCreate();
       context = getApplicationContext();
       in = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

   }

}

کلاسStruckNote

public class StruckNote {

   public String title;
   public String description;

}

لینک ارسال
به اشتراک گذاری در سایت های دیگر

چرا توسعه دهنده های ایرانی دوست دارن 2 سال قبل از تکنولوژی زندگی کنند ! خب دوست عزیز شما راحت با RecyclerView میتونید مشکلتون رو حل کنید

http://developer.android.com/training/material/lists-cards.html یه نمونه ساده ! اگه حل نشد بگید که یه کاری دیگه بکنم

لینک ارسال
به اشتراک گذاری در سایت های دیگر

ممنون از راهنمیتون :

نیشه بگید چطور میتونم از RecyclerView در کدهام قرار بدم ؟

نیاز به لایبری خاصی داره و یا اینکه برای هر اکتیویته که داخلش لیست ویو هست باید از RecyclerView استفاده بشه ؟

اگر زحمتی نیست بگید چطور در کدهام قرار بدم (کد رو در بالا قرار دادم )

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...