android - 从 editetext 获取文本并为 ListView 请求 json

标签 android

我想要一个搜索栏来搜索 json 文件并将其解析为 ListView ,我已经完成了对链接的解析,但我需要在编辑文本中输入的文本。这是我到目前为止得到的代码,它将在 edittext 中输入的文本放入 TextView :

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);
            }
        });

    }
}

希望有人能帮助我

最佳答案

所以您只想用按下按钮时 EditText 中的文本替换 TextView 中的文本?

尝试:

        @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);

关于android - 从 editetext 获取文本并为 ListView 请求 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29500502/

相关文章:

Android:一个对象的360度 View

android - 如何在 string.replace() 方法中设置值?

android - 滚动内容时将页脚导航固定在移动视口(viewport)的底部

java - Android 手机上的文本文件

javascript - 平板设备上的 Web 应用程序只有灰色

安卓谷歌地图错误

android - Android Studio 0.4.2错误[ContentElementType:FILE;文件:HtmlFile:incognito_mode_start_page.html]

Android工作室: Segmentation fault while trying to deploy app on Android device

android - ADB 和 Genymotion 错误 : "adb server is out of date. killing... cannot bind ' tcp:503 7' ADB server didn' t ACK"

android - 看不到第二个按钮