2015-04-07 52 views
1

我想要一个搜索栏来搜索json文件并将其解析为一个listview,我已经完成了解析链接,但我需要输入的文本编辑文本。这是我走到这一步的代码,它把已键入的EditText上一个TextView的文本:从editetext获取文本并请求列表视图的json

package it.experium.ccapp; 

import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

import org.w3c.dom.Text; 


public class MainActivity2Activity extends ActionBarActivity { 

    EditText edit; 
    TextView text; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main_activity2); 

     //setup ui 
     edit = (EditText) findViewById(R.id.editText4); 
     text = (TextView) findViewById(R.id.textView18); 
     Button b = (Button) findViewById(R.id.button_show); 

     //event handeling using onclick interface 
     b.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //getting the text from edittext 
       String name = edit.getText().toString(); 
       //appending the text to the textview 
       text.append(name); 
      } 
     }); 

    } 
} 

希望有人能帮助我

回答

1

所以你只是要替换的TextView文本您在按钮上的EditText文本中按下了哪些文本?

尝试:

 @Override 
     public void onClick(View v) { 
      //getting the text from edittext 
      String name = edit.getText().toString(); 
      //appending the text to the textview 
      text.setText(name); 
     } 

编辑

与参数创建的AsyncTask

  AsyncTask asyncTask= new AsyncTask(); 

      //create an object with your parameters 
      TaskParam param = new TaskParam("param1",name,"param2", 0); 
      asyncTask.execute(param); 
+0

如果你看过我的问题吧,我需要去申请一个JSON文本文件;) – Rik

+0

你没有实现一个AsyncTask?只需将文本传递给AsyncTask并将其发送到服务器 - 请参阅编辑 –