بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ

کمک ): سوالی در مورد ListView ها و استفاده از لینک به یک آدرس اینترنتی (حل شد)

مدیریت گفتگو
Majid Arabi 11 سال پیش
آخرین تغییر: 11 سال پیش

                         تشکر ویژه از دوست خوبم saeidhic  که کمک زیادی در حل این مشکل من کردند(:

سلام دوستان ...

این اولین برنامه من هست و اگه شما کمک کنید دیگه تا فردا یا پس فردا آماده میشه.

و فقط همین مرحله از کار مونده که از شما دوستای خوبم میخوام که کمکم کنید...

و اما سوال بنده : من میخوام وقتی که کاربر رو یک آیتمی از ListView تاچ کرد تا به صفحه بعد منتقل بشه، یک لینکی که مختص همون آیتم هست رو در Activity بعدی در یک Button ذخیره کنم تا وقتی کاربر اون Button رو زد به لینک مربوطه بره.

و اینکه من مثلا 50تا آیتم دارم تو لسیت ویوم و مسلماً 50تا هم لینک خواهم داشت تا در اکتیویتی دوم از اون لینک ها استفاده کنم.

من لینک هارو کجای اکتیویتی ، و چجوری ذخیره و  استفاده کنم.

من کد اکتیویتیی که Button در اون هست برای استفاده از لینک رو در زیر میزارم تا راحت تر کمکم کنید . . . 

فقط خواهشی که ازتون دارم اینه که کدی که باید استفاده کنم رو در یک پاسخ دیگه به من بدید که بدونم کجای اکتیویتی استفاده میشه.

public class ActivityStickerDescription extends Activity{

public String HTTP_URL;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Adad.setTestMode(true);
setContentView(R.layout.activity_sticker_description);
findViewById(R.id.imgBack).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
ActivityStickerDescription.this.finish();
}
});

Bundle extras = getIntent().getExtras();
if (extras != null){

String my_key_text = extras.getString("key_text");
int string_res_ID = getResources().getIdentifier(my_key_text, "string", getPackageName());
String my_message = " پیش نمایشی از استیکر " + getResources().getString(string_res_ID);

String imgName = "sticker_preview_" + getResources().getString(string_res_ID);
int image_res_ID = getResources().getIdentifier(imgName,"drawable",getPackageName());;

TextView tv = (TextView) findViewById(R.id.txtStickerDescription);
ImageView imageView = (ImageView) findViewById(R.id.imgStickerPreview);

imageView.setImageResource(image_res_ID);
tv.setText(my_message);

HTTP_URL = extras.getString("key_url");

}

findViewById(R.id.btnAddSticker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW , Uri.parse(HTTP_URL));
startActivity(intent);
}
});
}
}

نظرات

Majid Arabi 11 سال پیش
دوستان ازتون کمک خواستما ): کسی نیست یه کد به ما بده کارمون راه بیوفته):

پاسخ‌ها 6

saeidhic 11 سال پیش

سلام دوست عزیز

خب این کار خیلی ساده هستش اول سویچ کن رو پوزیشن لیست ویو 

بعد case هات رو اینجوری بنویس

 Intent intent = new Intent(first activity.class , SecondActivity.class);
intent.puExtra("key_value ", "http://linket.com/");
startActivity(intent);

این کار رو برای 50 تا آیتمت انجام بده فقط آدرس لینکت رو عوض کن

داخل اکتیویتی جدیدت هم این کار رو بکن

اول یه فیلد String در بالای کلاست تعریف کن  به نام : HTTP_URL

بعد بیا این کد هارو بزن:

 Bundel bundel = getIntent().getExtras();
if(bundel !=null){
HTTP_URL = bundel.getStringKey("key_value");
}

داخل رویداد کلیک دکمت این کد هارو بزن:

 Intetn intent = new Intent(Intent.ACTION_VIEW , Uri.parsUri(HTTP_URL);

و بعد هم استارت کن اکتیوتی رو 

به همین سادگی :)

نظرات

Majid Arabi 11 سال پیش
سعید جان میشه راهنمایی کنی که من چجوری باید سوییچ کنم به پوزیشن داخل لیست ویو . . . ببخشید من مبتدیم اگه میشه دقیق تر راهنمایی کنید ): ... ... ... الان پایین کد های اکتیویتی که لیست ویو رو داخل اون نوشتم رو میزارم اگه میشه رو اون کد ها تو ضیح بدید . . . البته الان داشتم تلاش میکردم که با راهنمایی که بالا کردی کارم رو انجام بدم ولی نتونستم ):
Majid Arabi 11 سال پیش

اینم اکتیویتی مربوط به لیست ویو :

public class ActivitySticker extends ListActivity{
public ListView lv;
public String keys_text;
public String[] my_items = new String[]{
"key_1" , "key_2" , "key_3" , "key_4" , "key_5" , "key_6" , "key_7" , "key_8" , "key_9" , "key_10",
"key_11", "key_12", "key_13", "key_14", "key_15", "key_16", "key_17", "key_18", "key_19", "key_20",
"key_21", "key_22", "key_23", "key_24", "key_25", "key_26", "key_27", "key_28", "key_29", "key_30",
"key_31", "key_32", "key_33", "key_34", "key_35", "key_36", "key_37", "key_38", "key_39", "key_40",
"key_41", "key_42", "key_43", "key_44", "key_45", "key_46", "key_47", "key_48",
};


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Adad.setTestMode(true);
setContentView(R.layout.activity_sticker);

findViewById(R.id.imgBack).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ActivitySticker.this.finish();
}
});

setListAdapter(new MyAdapter(this,
android.R.layout.simple_list_item_1,
R.id.textView1,
my_items));

lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {

Intent i = new Intent(getApplicationContext(), ActivityStickerDescription.class);
keys_text = String.valueOf(position+1);
i.putExtra("key_text", "key_" + keys_text);
startActivity(i);
}
});

}
private class MyAdapter extends ArrayAdapter<String>{

public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.sticker_list, parent, false);

String stringName = "key_" + String.valueOf(position+1);

int string_res_ID = getResources().getIdentifier(stringName,"string",getPackageName());
String my_string = getResources().getString(string_res_ID);

TextView tv = (TextView) row.findViewById(R.id.textView1);
tv.setText(my_string);

String imageName = "key_" + String.valueOf(position+1);
int image_res_ID = getResources().getIdentifier(imageName,"drawable",getPackageName());

ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
iv.setImageResource(image_res_ID);

return row;
}
}
}

نظرات

saeidhic 11 سال پیش

عزیز جان تابع setOnItemClickListener رو صدا بزن 

 public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch(position){
				case 0 :
Intent intent = new Intent(First.calss , Second.class);
intent.putExtra("key_valus" , "http://linke shome.com//");
startActivity(intent);
break; }

این کار رو برای همه ی آیتم هات انجام بده

50 تا آیتم داری 

case هات رو شماره هاش رو دونه دونه ببر بالا

لیست ویو پوزیشنش از شماره ی 0 شروع میشه پس تا 49 داری 

نظرات

saeidhic 11 سال پیش

دوست عزیز این اصلاحیه ی کلاس ActivityStricker

 public class ActivitySticker extends ListActivity{
public ListView lv;
public String keys_text;
public String[] my_items = new String[]{
"key_1" , "key_2" , "key_3" , "key_4" , "key_5" , "key_6" , "key_7" , "key_8" , "key_9" , "key_10",
"key_11", "key_12", "key_13", "key_14", "key_15", "key_16", "key_17", "key_18", "key_19", "key_20",
"key_21", "key_22", "key_23", "key_24", "key_25", "key_26", "key_27", "key_28", "key_29", "key_30",
"key_31", "key_32", "key_33", "key_34", "key_35", "key_36", "key_37", "key_38", "key_39", "key_40",
"key_41", "key_42", "key_43", "key_44", "key_45", "key_46", "key_47", "key_48",
    };
public String[] URLS = new String[]{
	"http://google.com" , "http://uncocoder.com" // be hamin tartib 50 ta linket ro inja mizari	
};
public static final String KEY_VALUE = "KEY";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Adad.setTestMode(true);
setContentView(R.layout.activity_main);

findViewById(R.id.imgBack).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
	ActivitySticker.this.finish();
            }
        });

setListAdapter(new MyAdapter(this,
android.R.layout.simple_list_item_1,
R.id.textView1,
my_items));

lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
	
	switch(position){
	case 0 :
		Intent intent0 = new Intent(ActivitySticker.this ,ActivityStickerDescription.class );
		intent0.putExtra(ActivitySticker.KEY_VALUE, URLS[0]);
		startActivity(intent0);
		break;
	case 1 :
		Intent intent1 = new Intent(ActivitySticker.this ,ActivityStickerDescription.class );
		intent1.putExtra(ActivitySticker.KEY_VALUE, URLS[1]);
		startActivity(intent1);
		break;
		//be hamin tartib case haro ezafe mikoni case 2 case 3 ta case 49 
		//shoamre ye araye ha ham mibari bala mishe URLS[2] 3 4 5 6 TA 49
		//INJA KEY_VALUE SABETE FAGHAT MEGHDAR HA FARGH DARAN
		}
            }
        });

    }
private class MyAdapter extends ArrayAdapter<String>{

public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
        }
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.sticker_list, parent, false);

String stringName = "key_" + String.valueOf(position+1);

int string_res_ID = getResources().getIdentifier(stringName,"string",getPackageName());
String my_string = getResources().getString(string_res_ID);

TextView tv = (TextView) row.findViewById(R.id.textView1);
tv.setText(my_string);

String imageName = "key_" + String.valueOf(position+1);
int image_res_ID = getResources().getIdentifier(imageName,"drawable",getPackageName());

ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
iv.setImageResource(image_res_ID);

return row;
        }
    }
}

نظرات

saeidhic 11 سال پیش

این هم اصلاحیه ی کلاس ActivityStickerDescription

 public class ActivityStickerDescription extends Activity{

public String HTTP_URL;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Adad.setTestMode(true);
setContentView(R.layout.activity_sticker_description);
findViewById(R.id.imgBack).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
ActivityStickerDescription.this.finish();
            }
        });

Bundle extras = getIntent().getExtras();
if (extras != null){

String my_key_text = extras.getString("key_text");
int string_res_ID = getResources().getIdentifier(my_key_text, "string", getPackageName());
String my_message = " پیش نمایشی از استیکر " +  getResources().getString(string_res_ID);

String imgName = "sticker_preview_" + getResources().getString(string_res_ID);
int image_res_ID = getResources().getIdentifier(imgName,"drawable",getPackageName());;

TextView tv = (TextView) findViewById(R.id.txtStickerDescription);
ImageView imageView = (ImageView) findViewById(R.id.imgStickerPreview);

imageView.setImageResource(image_res_ID);
tv.setText(my_message);

HTTP_URL = extras.getString(ActivitySticker.KEY_VALUE);

findViewById(R.id.btnAddSticker).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { //inja faghat havaset bashe age to barname didi khob amal nemikone ACTION_VIEW ro be ACTION_CHOOSER YA ACTION_PICK taghir bedi
Intent intent = new Intent(Intent.ACTION_VIEW , Uri.parse(HTTP_URL));
startActivity(intent);
            }
        });
    }
}

نظرات

Majid Arabi 11 سال پیش
حمید جان دستت درد نکنه که این همه کمکم کردی. . . ولی متاسفانه وقتی میخوام وارد اکتیویتی ActivityStickerDescription بشم این اکتیویتی کرش میکنه و کلا بر میگرده به اکتیویتی آغاز کننده برنامه . من سورس برنامه رو میزارم اگه زحمتی نیست یه نگاه بنداز ببین میتونی حلش کنی . اگرم که وقت نکردی نگاه کنی بازم آقایی کردی تا همینجاشم خیلی کمک بزگی به من کردی . . . مرسی .http://irandroid.gigfa.com/wp-content/uploads/2015/07/telegram_stickerFOR-DEBUG.rar
saeidhic 11 سال پیش
نه دوست عزیز این چه حرفیه هدفمون کلا این هست که دست هم رو بگیریم و به هم کمک کنیم تا دانش برنامه نویسیمون بره بالا من هر کمکی از دستم بربیاد دریغ نمیکنم :)
Majid Arabi 11 سال پیش
خیلی مردی داش سعید (:
saeidhic 11 سال پیش

سلام دوست عزیز من کد های برنامت رو کاملا اصلاح کردم و درست شده حتی یک تست هم گذاشتم میتونی خودت برنامه رو ران کنید و ببینی که چطور کار میکنه حتی احتمال خطاش رو هم برات گرفتم که تو تمام گوشی ها اجرا بشه حتی امولاتور :)

فقط باید زحمت بکشی و کیس هات رو ببری بالا و یه قسمت کوچیک از کد هارو کپی کنی و پیست کنی 

همچنین آدرس دقیق استیکر هات رو تو آرایه ی HTTP_URLS باید بریزی و ذخیره کنی 

این هم لینک پروژه دوست عزیز 

http://s3.picofile.com/file/8200432500/telegram_sticker.zip.html

ایشالله که موفق باشی از برنامه ی خوبتم خیلی لذت بردم طراحیش حرف نداشت

شاید خودم اولین نفری باشم که از مارکت ها دانلودش میکنم :)

به امید موفقیت روز افزون شما دوست عزیز :)

نظرات

Majid Arabi 11 سال پیش
نمیدونم چی بگم آقا سعید .واقعا لطف کردی ایشالا به یه طریقی بتونم جبران کنم...چون اولین برنامم هست تو فهم و استفاده از کدها مشکل دارم(: در ضمن شما لطف داری ممنونم به خاطر نظرتون درباره طراحی برنامه... ایشالا به زودی میزارمش تو بازار......خیلی آقایی کردی بازم ممنون(:
saeidhic 11 سال پیش
من کاری نکردم که 99% کار ها پای خودت بوده :) انشاالله موفق باشی :) به امید نرم افزار های بیشتر ازت

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .