i want to make a array of stringin listview android so i used this code but evry time eclipse say The constructor ArrayAdapter(listefriends.connect, int, String) is undefined in this line so how can help me :
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.listview, user);
codes java:
public class listefriends extends Activity {
ListView tvhttp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.friends);
setContentView(R.layout.activity_list_item);
tvhttp= ((ListView)findViewById(R.id.tvhttp));
connect obj = new connect ();
obj.execute("http://development.www.chatpassion.org/androidchat/friends.php?username=yassine11");
}
public class connect extends AsyncTask<String , Void , String>
{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
BufferedReader reader = null;
String data = null;
try {
HttpClient client = new DefaultHttpClient();
URI uri = new URI(params[0]);
HttpGet get = new HttpGet(uri);
HttpResponse response = client.execute(get);
InputStream stream = response.getEntity().getContent();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer("");
String line ="";
while ((line = reader.readLine()) !=null){
buffer.append(line);
}
reader.close();
data = buffer.toString();
return data;
}catch (URISyntaxException e){
e.printStackTrace();}
catch (ClientProtocolException e){
e.printStackTrace();}
catch (IOException e){
e.printStackTrace();}
finally {
if (reader !=null){
try {
reader.close();}
catch (Exception e){Log.i("error", e.toString());}
}
}
return null;
}
@Override
protected void onPostExecute(String result)
{
super.onPostExecute ( result);
JSONObject json;
//JSONObject objet2;
try {
json = new JSONObject(result);
//tvhttp.setText(json.toString(2));
JSONArray jsonArray = json.getJSONArray("FriendsList");
String user = null ;
for (int j = 0; j < jsonArray.length(); j++) {
JSONObject jsonObjectData1 = jsonArray.getJSONObject(j);
String username = jsonObjectData1.getString("username");
String avatar = jsonObjectData1.getString("avatar");
user = avatar.concat(username);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.activity_list_item,user);
tvhttp.setAdapter(adapter);
//Log.i("tessssssssssst", user);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
the layout listview :
<?xml version="1.0" encoding="utf-8"?>
<!-- Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >
</TextView>
the layout of main :
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/tvhttp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>