Foros del Web » Programando para Internet » Android »

Pasar varios txt a distintos clicks de listview

Estas en el tema de Pasar varios txt a distintos clicks de listview en el foro de Android en Foros del Web. Hola buenas, tengo un problema con una lista lo explico: Tengo un listview con unos items cargados, quiero que al hacer click en esa lista ...
  #1 (permalink)  
Antiguo 27/08/2013, 00:43
 
Fecha de Ingreso: julio-2013
Mensajes: 36
Antigüedad: 10 años, 9 meses
Puntos: 2
Pasar varios txt a distintos clicks de listview

Hola buenas, tengo un problema con una lista lo explico:

Tengo un listview con unos items cargados, quiero que al hacer click en esa lista me lea unos txt que estan asociados a cada item. El problema es que uno si que lo leo, pero cuando quiero pasarle los demas, al tener que hacer un metodo genérico que lea los txt, no consigo hacerlo.

Espero que puedan ayudarme....Mi código es el siguiente:


Código Java:
Ver original
  1. protected void onCreate(Bundle savedInstanceState) {
  2.         super.onCreate(savedInstanceState);
  3.         // Display a indeterminate progress bar on title bar
  4.         requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  5.         setContentView(R.layout.activity_main);
  6.         this.listView = (ListView) findViewById(R.id.listView);
  7.         this.et1 = (EditText) findViewById(R.id.et1);
  8.         final ArrayList<Item> items=new ArrayList<Item>();
  9.         items.add(new Item(R.drawable.powerpoint,"Tu powerpoint, mejor si le falta algo(Jul 2013)",null,(new File("tu_powerpoint_mejor_si_le_falta_algo_1.txt"))));
  10.         items.add(new Item(R.drawable.basededatos,"El centro de tu aplicación ya no es la base de datos (Jun 2013)",null,(new File("prueba.txt"))));
  11.         // Sets the data behind this ListView
  12.         this.listView.setAdapter(new ItemAdapter(this, items));
  13.         // Register a callback to be invoked when an item in this AdapterView
  14.         // has been clicked
  15.         listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  16.         @SuppressLint("SetJavaScriptEnabled")
  17.         @Override
  18.         public void onItemClick(AdapterView<?> adapter, View view,
  19.         int position, long arg) {
  20.             // Load the text
  21.             Item item = (Item) listView.getAdapter().getItem(position);
  22.             et1.setText(leer(archivo));
  23.         }});
  24.     }
  25.    
  26.     /** Metodo para leer archivo de texto
  27.      * @param items Ruta del archivo de texto en la carpeta ASSETS
  28.      * @throws IOException
  29.      * @throws FileNotFoundException
  30.      * */
  31.      public String leer(String archivo ) {
  32.    
  33.          String texto="";
  34.          String linea = null;
  35.          try {
  36.          InputStream in = getAssets().open( archivo );
  37.          if (in != null) {
  38.          InputStreamReader input = new InputStreamReader(in);
  39.          BufferedReader buffreader = new BufferedReader(input);
  40.          while
  41.              ((linea = buffreader.readLine()) != null) {
  42.              texto +=linea;
  43.             }
  44.                 in.close();
  45.             }
  46.          } catch (IOException e) {
  47.          e.printStackTrace();
  48.          }
  49.         return texto;
  50.          }


Muchas Gracias de antemano y un saludo

Última edición por razpeitia; 27/08/2013 a las 07:43

Etiquetas: activity, clicks, distintos, java, listview, txt
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:36.