مشکل در عدم نمایش اطلاعات در list view
با سلام
برنامه ای که نوشتم وقتی اجرا میگیرم محتویات را در لیست ویو نمایش نمیده اینم کد هاش:
package com.mobtakerangolpa.app.mysite;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Arrays;
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class Main extends ListActivity {
String[] id, name, content, commentcount;
String tid, tname, tcontent, tcomment;
private int page = 1;
private int count;
private String res = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new getpost().execute();
}
private void makearray(int c) {
id = new String[c];
name = new String[c];
content = new String[c];
commentcount = new String[c];
Arrays.fill(name, "");
}
public class getpost extends AsyncTask {
@Override
protected Object doInBackground(Object... arg0) {
try {
String data = URLEncoder.encode("page", "utf8") + "=" + URLEncoder.encode(page + "", "utf8");
URL link = new URL("http://192.168.1.103:8080/wordpress/app/getpost.php");
URLConnection connect = link.openConnection();
//send data
connect.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(connect.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
res = sb.toString();
for (int y = 0; y < 4; y++) {
if (res.charAt(y) == '☻') {
count = Integer.parseInt(res.substring(0, y));
res = res.substring(y + 1);
break;
}
}
makearray(count);
int f = 0, c = 0;
for (int i = 0; i < res.length(); i++) {
if (res.charAt(i) == '☻') {
String temp = res.substring(f, i);
if (c == 0) {
tid = temp;
}
if (c == 1) {
tname = temp;
}
if (c == 2) {
tcontent = temp;
}
if (c == 3) {
tcomment = temp;
for (int t = 0; t < count; t++) {
if (name[t].equals("")) {
id[t] = tid;
name[t] = tname;
content[t] = tcontent;
commentcount[t] = tcomment;
break;
}
}
c = -1;
}
f = i + 1;
c += 1;
}
}
}
catch (Exception e) {
res = e.toString();
}
return "";
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
setListAdapter(new IA());
}
}
public class IA extends ArrayAdapter<String> {
public IA() {
super(Main.this, R.layout.row_main, name);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater in = getLayoutInflater();
View row = in.inflate(R.layout.row_main, parent, false);
TextView titr = (TextView) findViewById(R.id.row_main_titr);
TextView matn = (TextView) findViewById(R.id.row_main_content);
TextView extra = (TextView) findViewById(R.id.row_main_extra);
TextView img = (TextView) findViewById(R.id.row_main_image);
titr.setText(name[position]);
titr.setText(content[position]);
titr.setText("نظرات :" + commentcount[position]);
return (row);
}
}
}
package com.mobtakerangolpa.app.mysite;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Arrays;
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class Main extends ListActivity {
String[] id, name, content, commentcount;
String tid, tname, tcontent, tcomment;
private int page = 1;
private int count;
private String res = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new getpost().execute();
}
private void makearray(int c) {
id = new String[c];
name = new String[c];
content = new String[c];
commentcount = new String[c];
Arrays.fill(name, "");
}
public class getpost extends AsyncTask {
@Override
protected Object doInBackground(Object... arg0) {
try {
String data = URLEncoder.encode("page", "utf8") + "=" + URLEncoder.encode(page + "", "utf8");
URL link = new URL("https://192.168.1.103:8080/wordpress/app/getpost.php");
URLConnection connect = link.openConnection();
//send data
connect.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(connect.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
res = sb.toString();
for (int y = 0; y < 4; y++) {
if (res.charAt(y) == '☻') {
count = Integer.parseInt(res.substring(0, y));
res = res.substring(y + 1);
break;
}
}
makearray(count);
int f = 0, c = 0;
for (int i = 0; i < res.length(); i++) {
if (res.charAt(i) == '☻') {
String temp = res.substring(f, i);
if (c == 0) {
tid = temp;
}
if (c == 1) {
tname = temp;
}
if (c == 2) {
tcontent = temp;
}
if (c == 3) {
tcomment = temp;
for (int t = 0; t < count; t++) {
if (name[t].equals("")) {
id[t] = tid;
name[t] = tname;
content[t] = tcontent;
commentcount[t] = tcomment;
break;
}
}
c = -1;
}
f = i + 1;
c += 1;
}
}
}
catch (Exception e) {
res = e.toString();
}
return "";
}
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
setListAdapter(new IA());
}
}
public class IA extends ArrayAdapter<String> {
public IA() {
super(Main.this, R.layout.row_main, name);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater in = getLayoutInflater();
View row = in.inflate(R.layout.row_main, parent, false);
TextView titr = (TextView) findViewById(R.id.row_main_titr);
TextView matn = (TextView) findViewById(R.id.row_main_content);
TextView extra = (TextView) findViewById(R.id.row_main_extra);
TextView img = (TextView) findViewById(R.id.row_main_image);
titr.setText(name[position]);
titr.setText(content[position]);
titr.setText("نظرات :" + commentcount[position]);
return (row);
}
}
}
link log file :
http://s6.picofile.com/file/8203327934/log.txt.html
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
