بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
بچه خواهشا جواب بدید
مدیریت گفتگو
آخرین تغییر: 11 سال پیش
ترو خدا یکی به سوالم جواب بده من با استفاده از اموزشی که استاد دادند (feed reader) تونستم خبر های سایت مثلا زومیت رو بخونم ولی نمیدونم چطوری میتونم عکس های اون خبر رو هم بگیرم .تو استک خیلی سرچ زدم اما هیچی که هیچی کمکم کنید .خواهش میکنم
پاسخها 2
خیلی عذر می خوام که دیر شد.
من از لینک @Criss استفاده کردم. ولی بجای ادرس سایت بهش متن داخل تگ description فید زومیت رو دادم.
این کد اکتیوتی:
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
// URL Address
String url = "<html><title>۸۰ درصد صاحبان اپل واچ از سیستم پرداخت اپلپِی استفاده میکنند</title><img src=\"http://zoomit.ir/media/k2/items/cache/2e5898737730df3b1c6dc0608a7c553e_XL.jpg\" alt=\"اپل واچ\"/></div><div class=\"K2FeedIntroText\"><p>بر اساس اطلاعات به دست آمده از وبسايت Wristly که معمولا آمار درآمد شرکت <a href=\"http://zoomit.ir//apple\" target=\"_blank\">اپل </a>را ثبت ميکند، بيش از ?? درصد از صاحبان اپل واچ در آمريکا و بريتانيا از سيستم پرداخت اپل پِي استفاده ميکنند.</p></html>";
ProgressDialog mProgressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Locate the Buttons in activity_main.xml
Button titlebutton = (Button) findViewById(R.id.titlebutton);
Button descbutton = (Button) findViewById(R.id.descbutton);
Button logobutton = (Button) findViewById(R.id.logobutton);
// Capture button click
titlebutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Execute Title AsyncTask
new Title().execute();
}
});
// Capture button click
descbutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Execute Description AsyncTask
new Description().execute();
}
});
// Capture button click
logobutton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Execute Logo AsyncTask
new Logo().execute();
}
});
}
// Title AsyncTask
private class Title extends AsyncTask<Void, Void, Void> {
String title;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setTitle("Android Basic JSoup Tutorial");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Connect to the web site
Document document = Jsoup.parse(url, "UTF-8");
// Get the html document title
title = document.title();
return null;
}
@Override
protected void onPostExecute(Void result) {
// Set title into TextView
TextView txttitle = (TextView) findViewById(R.id.titletxt);
txttitle.setText(title);
mProgressDialog.dismiss();
}
}
// Description AsyncTask
private class Description extends AsyncTask<Void, Void, Void> {
String desc;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setTitle("Android Basic JSoup Tutorial");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Connect to the web site
Document document = Jsoup.parse(url, "UTF-8");
// Using Elements to get the Meta data
Elements descriptions = document.select("p");
// Locate the content attribute
for (Element description : descriptions) {
desc = description.ownText();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Set description into TextView
TextView txtdesc = (TextView) findViewById(R.id.desctxt);
txtdesc.setText(desc);
mProgressDialog.dismiss();
}
}
// Logo AsyncTask
private class Logo extends AsyncTask<Void, Void, Void> {
Bitmap bitmap;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setTitle("Android Basic JSoup Tutorial");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
Log.i("LOG", "Start Image");
// Connect to the web site
Document document = Jsoup.parse(url, "UTF-8");
// Using Elements to get the class data
Elements img = document.select("img");
// Locate the src attribute
String imgSrc = img.attr("src");
// Download image from URL
InputStream input;
input = new java.net.URL(imgSrc).openStream();
bitmap = BitmapFactory.decodeStream(input);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Decode Bitmap
return null;
}
@Override
protected void onPostExecute(Void result) {
// Set downloaded image into ImageView
ImageView logoimg = (ImageView) findViewById(R.id.logo);
logoimg.setImageBitmap(bitmap);
mProgressDialog.dismiss();
}
}
}
نظرات
این هم فایل 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" >
<TextView
android:id="@+id/titletxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />
<Button
android:id="@+id/titlebutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/titletxt"
android:text="@string/Title" />
<TextView
android:id="@+id/desctxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titlebutton"
android:layout_centerInParent="true"
android:gravity="center" />
<Button
android:id="@+id/descbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/desctxt"
android:text="@string/Description" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/descbutton"
android:layout_centerInParent="true" />
<Button
android:id="@+id/logobutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/logo"
android:text="@string/Logo" />
</RelativeLayout>
نظرات
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات