I am trying to import text from a web page hosted on the server I have the java file as below
public class News extends Activity
{
TextView txtview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.txt_news);
txtview =(TextView) findViewById(R.id.textView1);
try
{
HttpClient htc=new DefaultHttpClient();
HttpPost htp=new HttpPost("http://www.aaaa.com/a.php");
HttpResponse res=htc.execute(htp);
HttpEntity ent=res.getEntity();
InputStream web=ent.getContent();
try
{
BufferedReader reader=new BufferedReader(new InputStreamReader(web,"iso-8895-1"),8);
txtview.setText(reader.readLine());
web.close();
}
catch(Exception e)
{
Log.e("log_tag","Error"+e.toString());
}
} catch(Exception e)
{
Log.e("log_tag","Error"+e.toString());
}
finally
{
}
}
}
and the layout xml coded like :
<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="@drawable/news_bg"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="240dp"
android:textColor="#000" />
</RelativeLayout>
In manifest i have also included the internet connection permission syntax but i dont get any text from hosted file a.php
the code in a.php:
<?php
$t="hello buddy";
print json_encode($t);
?>
please help to resolve the problem the text view is not showing the $t variable content hello buddy.how to do that.... screen of layout.xml appears but there is no text in textview.