Hi all,
I'm trying to realize a little Feed in Android.... The problem is I got an
error and I don't know why.... The problem is on the onClick function inside
onCreate... I got an error connected with the EditText. Does anyone know
why????
Thks
Maurizio
package eu.reply.sytel;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class GFeed extends Activity {
 static final int SET_FEED = Menu.FIRST;
 static final int XML_EXTRACTOR = 1;

  private TextView feed_l;
 private EditText feed_t;
 private Button feed_b;

 /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  // getting the UI IDs
  feed_l = (TextView) this.findViewById(R.id.feed_l);
  feed_t = (EditText) this.findViewById(R.id.feed_t);
  feed_b = (Button) this.findViewById(R.id.feed_b);
  // setting on click event on OK button
  feed_b.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View arg0) {
  String feed_URL = feed_t.getText().toString();
  retrieveFeed(feed_URL);
  }

  });
  }

  protected void retrieveFeed(String feed_URL) {

  try {
  URL url = new URL(feed_URL);

  URLConnection connection = url.openConnection();
  HttpURLConnection httpConnection = (HttpURLConnection) connection;

  int responseCode = httpConnection.getResponseCode();
  if (responseCode == HttpURLConnection.HTTP_OK){
  //InputStream in = httpConnection.getInputStream();
  Toast.makeText(GFeed.this, "OK", Toast.LENGTH_LONG);
  }
  else {
  Toast.makeText(GFeed.this, "Wrong", Toast.LENGTH_LONG);
  }
  } catch (MalformedURLException e) {
  Toast.makeText(GFeed.this, "Wrong", Toast.LENGTH_LONG);
  } catch (IOException e) {
  Toast.makeText(GFeed.this, "Wrong", Toast.LENGTH_LONG);
  }
 }

 /** Called to create the options menu **/
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);
  // adding menu items
  menu.add(0, SET_FEED, Menu.NONE, R.string.setFeed);

  return true;
 }

 /** Called when an options menu item is selected **/
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  super.onOptionsItemSelected(item);

  switch (item.getItemId()) {
  case (SET_FEED): {
  showFeedPrompt();
  return true;
  }
  }

  return false;
 }

 private void showFeedPrompt() {
  // showing the elements to set a new feed
  feed_l.setVisibility(View.VISIBLE);
  feed_t.setVisibility(View.VISIBLE);
  feed_b.setVisibility(View.VISIBLE);
 }

 private void hideFeedPrompt() {
  // hiding the elements to set a new feed
  feed_l.setVisibility(View.GONE);
  feed_t.setVisibility(View.GONE);
  feed_b.setVisibility(View.GONE);
 }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to