JSON Facebook.
?
: -
1: - , JSON TEXTVIEW.
2: - , , :) textview GetText().ToString
3: - facebook.
4: - , , , . u ,
5: -
tv.setVisibility(View.GONE)
facebook..
facebook textview , : D
...
I place it at the click of a button
1)
tv= (TextView)findViewById(R.id.tv);
click=(Button)findViewById(R.id.btn1);
click.setOnClickListener(mthdpost);
2) add a click event to this button
private View.OnClickListener mthdpost=new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String json = "{"
+ " \"name\": \"myName\", "
+ " \"message\": [\"myMessage1\",\"myMessage2\"],"
+ " \"place\": \"myPlace\", "
+ " \"date\": \"thisDate\" "
+ "}";
JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
String name = object.getString("name");
String place = object.getString("place");
String date = object.getString("date");
JSONArray message = object.getJSONArray("message");
String MessageToPost= null;
tv.setText("Name: "+ name +"\n\n");
tv.append("Place: "+ place +"\n\n");
tv.append("Date: "+ date +"\n\n");
for(int i=0;i<message.length();i++)
{
tv.append("Message: "+ message.getString(i) +"\n\n");
}
MessageToPost=tv.getText().toString();
postToWall(MessageToPost);
} catch (JSONException e)
{e.printStackTrace();
}
catch(Exception ex)
{ex.printStackTrace();}
}
};
3) message sending method
public void postToWall(String msg){
Log.d("Tests", "Testing graph API wall post");
try {
String response = facebook.request("me");
Bundle parameters = new Bundle();
parameters.putString("message", msg);
parameters.putString("description", "test test test");
response = facebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} catch(Exception e) {
e.printStackTrace();
}
}
HOPE THAT HELP :)
source
share