کندی در ایتم لیست ویو! فوری هست میخوام برنامه رو تحویل بدم!
سلام بنده یه لیست ویو ساختم که ایتم هاش از (txt) هست ، یه سری مطالب قرار دادم
خوده لیست ویو کندی نداره اما توی ایتم ها ( مطلب ) کلا کنده
مثلا یه دکمه واسه برگشت زدم خیلی کند برمیگرده و وقتی کی مطلب رو ادامه میکنی ( میری به سمت پایین) کند هست
البته بگم وقتی یه صفحه تنظیمات تغییر فونت ساختم کند شد.
خب دوستان گفتند که باید کد هارو توی trhead بزارم خب نمیدونم کدوم قسمتش بزارم
میشه راهنمایی کنید؟
کد اکتویتی صفحه مطالب ( show ) :
package dashti.ahmad.app.baby;
import java.io.IOException;
import java.io.InputStream;
import dashti.ahmad.app.baby.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.provider.MediaStore.Images.ImageColumns;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class showmatn extends Activity {
Typeface yekan, koodak, nazanin, titr;
public static ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
ImageView img_share = (ImageView) findViewById(R.id.img_share);
ImageView img_doorexit = (ImageView) findViewById(R.id.img_doorexit);
final TextView tv = (TextView) findViewById(R.id.text_matn);
final int show = getIntent().getExtras().getInt("show");// in text az
// raw migire
String displayMatn = "";
InputStream Matn = null;
try {
switch (show) {
case 1:
Matn = getResources().openRawResource(R.raw.yek);
break;
case 2:
Matn = getResources().openRawResource(R.raw.doo);
break;
case 3:
Matn = getResources().openRawResource(R.raw.se);
break;
case 4:
Matn = getResources().openRawResource(R.raw.chare);
break;
case 5:
Matn = getResources().openRawResource(R.raw.panj);
break;
case 6:
Matn = getResources().openRawResource(R.raw.shish);
break;
case 7:
Matn = getResources().openRawResource(R.raw.haft);
break;
case 8:
Matn = getResources().openRawResource(R.raw.hasht);
break;
case 9:
Matn = getResources().openRawResource(R.raw.noh);
break;
case 10:
Matn = getResources().openRawResource(R.raw.dah);
break;
}
int fileLen = Matn.available();
byte[] fileBuffer = new byte[fileLen];
Matn.read(fileBuffer);
Matn.close();
displayMatn = new String(fileBuffer);
String s2 = displayMatn;
tv.setText(s2);
} catch (IOException e) {
}
tv.setText(displayMatn);
img_share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String m_show = tv.getText().toString();
Intent inshare = new Intent(Intent.ACTION_SEND);
inshare.setType("text/plain");
inshare.putExtra(Intent.EXTRA_TEXT, m_show);
startActivity(Intent.createChooser(inshare,
"اشتراک گذاری متن با"));
}
});
img_doorexit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showmatn.this.finish();
}
});
}
}
این قسمت از کدت رو داخل thread بذار
img_share.setOnClickListener(newOnClickListener(){
@Override
publicvoid onClick(View arg0){
String m_show = tv.getText().toString();
Intent inshare =newIntent(Intent.ACTION_SEND);
inshare.setType("text/plain");
inshare.putExtra(Intent.EXTRA_TEXT, m_show);
startActivity(Intent.createChooser(inshare,
"اشتراک گذاری متن با"));
}
سلام ارور میده و قابل اصلاح نیست
Runnable runnable = new Runnable() {
public void run() {
img_share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String m_show = tv.getText().toString();
Intent inshare = new Intent(Intent.ACTION_SEND);
inshare.setType("text/plain");
inshare.putExtra(Intent.EXTRA_TEXT, m_show);
startActivity(Intent.createChooser(inshare,
"اشتراک گذاری متن با"));
}
}
};
Thread myThread = new Thread(runnable);
myThread.start();
});
{ آخری ارور میده اگه حذفش کنم شیر ( share ) ارور میده اما اگه اضافه کنم دکمه ای که برای برگشت ساختم زیرش ارور میده
runOnUiThread(new Runnable() {
@Override
public void run() {
img_share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String m_show = tv.getText().toString();
Intent inshare = new Intent(Intent.ACTION_SEND);
inshare.setType("text/plain");
inshare.putExtra(Intent.EXTRA_TEXT, m_show);
startActivity(Intent.createChooser(inshare,
"اشتراک گذاری متن با"));
}
});
});
این رو تو کد هات بزن ببین مشکلت حل میشه
listView.setScrollingCacheEnabled(false);
اگه نشد اینو امتحان کن
تو فایل xml
android:cacheColorHint="#00000000"
سلام بنده به دوستم گفتم گفت بخاطر Scroll View هست ، کد رو کجای اکتویتی بزارم؟ اررور میده ، کد پایینی رو هم توی XML گذاشتم اما هیچ تغییری نکرد!
ببنید:
به کد زیر دقت کنید:
ListView listview = (ListView)findViewById(R.id.listview);
listview.setScrollingCacheEnable(false);
منظورم کندی خوده لیست ویو نیست ها ؟؟ ، منظورم داخلش مثلا این لیست ویو بنده هست:
1.ایران کجاست؟
2.ایران دلیران
3.یاد بگیرید
بعد مثلا روی 3.یاد بگیرید کلیک میکنم بعد مثلا میام پایین کند میاد پایین
کد اکتویتی لیست ویو:
package dashti.ahmad.app.baby;
import dashti.ahmad.app.baby.R;
import dashti.ahmad.app.baby.showmatn;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Fehrest extends Activity {
String[] str = {
"بهترین ها",
"قدرتمندان",
"دلیران"
}; //in name item
public static ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fehrestmataleb);
//Toast.makeText(this,str[arg2], Toast.LENGTH_LONG).show();
ListView lv = (ListView) findViewById(R.id.listView1);//tarif id listview
//adaptor
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.list_ad, str);//adaptor
lv.setAdapter(adapter);//set kardan list view ba adaptor
lv.setOnItemClickListener(new OnItemClickListener() {//baraye har item ye roidad select gozashtan
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
switch (arg2) {// ba estefade shart switch
case 0://item one list view
Intent intent0 = new Intent(Fehrest.this, showmatn.class);
intent0.putExtra("show", 1);
startActivity(intent0);
Toast.makeText(getApplicationContext(), str[arg2], Toast.LENGTH_LONG).show();
break;
case 1://item two
Intent intent1 = new Intent(Fehrest.this, showmatn.class);
intent1.putExtra("show", 2);
startActivity(intent1);
Toast.makeText(getApplicationContext(), str[arg2], Toast.LENGTH_LONG).show();
break;
case 2://item three
Intent intent2 = new Intent(Fehrest.this, showmatn.class);
intent2.putExtra("show", 3);
startActivity(intent2);
Toast.makeText(getApplicationContext(), str[arg2], Toast.LENGTH_LONG).show();
break;
case 3://item four
Intent intent3 = new Intent(Fehrest.this, showmatn.class);
intent3.putExtra("show", 4);
startActivity(intent3);
Toast.makeText(getApplicationContext(), str[arg2], Toast.LENGTH_LONG).show();
break;
default://megdar default yani agr hich gozine az bala nbod in select shodas
Toast.makeText(getApplicationContext(), "! یافت نشد", Toast.LENGTH_LONG).show();
break;
}
}
});
}
}
کد XML لیست ویو:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F9E6FB"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="dashti.ahmad.app.baby.MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:padding="10dip"
android:divider="#000000"
android:dividerHeight="5dip">
</ListView>
</RelativeLayout>
کد Xml داخل لیست ویو ( مطالب ):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF4F88" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center" >
<ImageView
android:id="@+id/img_doorexit"
android:layout_width="70dip"
android:layout_height="70dip"
android:src="@drawable/img_door" />
<ImageView
android:id="@+id/img_share"
android:layout_width="70dip"
android:layout_height="70dip"
android:layout_marginLeft="28dip"
android:src="@drawable/img_share" />
</LinearLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1"
android:layout_marginTop="16dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<dashti.ahmad.app.baby.CustomTextView
android:id="@+id/text_matn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="@string/app_name"
android:textColor="#000"
android:textSize="18dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
کد اکتیویتی داخل لیست ویو ( مطالب) :
package dashti.ahmad.app.baby;
import java.io.IOException;
import java.io.InputStream;
import dashti.ahmad.app.baby.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.provider.MediaStore.Images.ImageColumns;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class showmatn extends Activity {
Typeface yekan, koodak, nazanin, titr;
public static ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
ImageView img_share = (ImageView) findViewById(R.id.img_share);
ImageView img_doorexit = (ImageView) findViewById(R.id.img_doorexit);
final TextView tv = (TextView) findViewById(R.id.text_matn);
final int show = getIntent().getExtras().getInt("show");// in text az
// raw migire
String displayMatn = "";
InputStream Matn = null;
try {
switch (show) {
case 1:
Matn = getResources().openRawResource(R.raw.yek);
break;
case 2:
Matn = getResources().openRawResource(R.raw.doo);
break;
case 3:
Matn = getResources().openRawResource(R.raw.se);
break;
}
int fileLen = Matn.available();
byte[] fileBuffer = new byte[fileLen];
Matn.read(fileBuffer);
Matn.close();
displayMatn = new String(fileBuffer);
String s2 = displayMatn;
tv.setText(s2);
} catch (IOException e) {
}
tv.setText(displayMatn);
img_share.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String m_show = tv.getText().toString();
Intent inshare = new Intent(Intent.ACTION_SEND);
inshare.setType("text/plain");
inshare.putExtra(Intent.EXTRA_TEXT, m_show);
startActivity(Intent.createChooser(inshare,
"اشتراک گذاری متن با"));
}
});
img_doorexit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
showmatn.this.finish();
}
});
}
}
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .