结合数据安卓成语字典

package com.example.superb.zidian;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
//import android.support.v7.app.LinearLayoutManager;
//import android.support.v7.app.RecyclerView;

//import com.haocent.android.recyclerview.R;

import com.kymjs.rxvolley.RxVolley;
import com.kymjs.rxvolley.client.HttpCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**

  • 绾靛悜甯冨眬 鐨?Activity
  • Created by Tnno Wu on 2018/03/05.
    */

public class VerticalActivity extends AppCompatActivity {
public static final String WORD_KEY = “f98139cfac1da1eed4810e33d0d51a11”;//鍦ㄨ仛鍚堟暟鎹噷闈㈢敵璇风殑浜у搧绉橀挜锛屾嫢鏈夌閽ユ墠鑳藉幓璁块棶杩欎釜缃戝潃

private EditText editword;

private TextView result,result1,result2;

private Handler handler;

private Button button;
//private static final String TAG = VerticalActivity.class.getSimpleName();

private List<String> mList = new ArrayList<>();





String pinyin,tongyi,fanyi,chengyujs,from_,yinzhengjs;


















@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.vertical_activity);
    initialize();
    initData();
    //initView();
   initView();
}


private void initialize() {

    editword = (EditText) findViewById(R.id.edit_word);

    result = (TextView) findViewById(R.id.result);

    button= (Button) findViewById(R.id.button);



}


private void initData() {

    button.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View view) {

            switch (view.getId()){

                case R.id.button:
                    Log.e("ssssss", "onsssssssssssssssssssssss");
                    final String edit_result=editword.getText().toString();
                    mList = new ArrayList<>();
                    handler= new Handler() {

                        @Override

                        public void handleMessage(final Message msg) {//handler鍔燭hread缁勬垚寮傛绾跨▼璁块棶缃戠粶

                            super.handleMessage(msg);

                            switch (msg.what) {

                                case 1:

                                    if (edit_result!=null) {

                                        String url= "http://v.juhe.cn/chengyu/query?key="+ WORD_KEY+"&word="+edit_result;

                                        RxVolley.get(url, new HttpCallback() {

                                            @Override

                                            public void onSuccess(String t) {//瀛楃涓叉槸涓€涓猨son鏍煎紡鐨勫瓧绗︿覆锛孯xVolley鏄闂綉缁滅殑涓€涓鏋讹紝鏄坊鍔犵殑渚濊禆

                                                super.onSuccess(t);

                                               mList.add(parseJson(t));

//+’\n’+tongyi+’\n’+fanyi+’\n’+chengyujs+’\n’+from_+’\n’+yinzhengjs+’\n’
mList.add("鍚屼箟璇嶏細 "+tongyi+’\n’+"鍙嶄箟璇嶏細 "+fanyi);
mList.add(“鍚箟锛?”+chengyujs);
mList.add(“搴斿緛瑙i噴锛?”+yinzhengjs);
mList.add(“鍑哄锛?”+from_);
result.setText(from_);
initView();

                                            }

                                        });

                                        break;

                                    }else{

                                        Toast.makeText(VerticalActivity.this, "杈撳叆鐨勬垚璇负绌?+edit_result, Toast.LENGTH_SHORT).show();

                                    }

                            }



                        }

                    };

                    new Thread(){

                        @Override

                        public void run() {

                            super.run();

                            Message message=new Message();

                            message.what=1;

                            handler.sendMessage(message);

                        }

                    }.start();



                    break;

            }

        }

    });



}









private String parseJson(String t) {//瑙f瀽json瀛楃涓?
    String s="";

    try {

        JSONObject jsonObject = new JSONObject(t);

        JSONObject result = jsonObject.getJSONObject("result");



         pinyin=result.getString("pinyin");

       chengyujs = result.getString("chengyujs");

       from_=result.getString("from_");

         yinzhengjs=result.getString("yinzhengjs");

        s=chengyujs+from_+yinzhengjs;

         tongyi = result.getString("tongyi");

        // s=s+tongyi;

        s=chengyujs+from_+yinzhengjs+tongyi;

       fanyi = result.getString("fanyi");

        s=pinyin;










        //s=s+fanyi;

        //s=chengyujs;

    } catch (JSONException e) {

        e.printStackTrace();

    }

return s;

}









private void initView() {
    VerticalAdapter adapter = new VerticalAdapter(this);

    RecyclerView rcvVertical = findViewById(R.id.rcv_vertical);

    LinearLayoutManager managerVertical = new LinearLayoutManager(this);
    managerVertical.setOrientation(LinearLayoutManager.VERTICAL);

    // 涔熷彲浠ョ洿鎺ュ啓鎴愶細

// rcvVertical.setLayoutManager(new LinearLayoutManager(this));

    rcvVertical.setLayoutManager(managerVertical);
    rcvVertical.setHasFixedSize(true);
    rcvVertical.setAdapter(adapter);

    adapter.setVerticalDataList(mList);
}

}

package com.example.superb.zidian;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.*;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

//import com.haocent.android.recyclerview.R;

import java.util.ArrayList;
import java.util.List;

/**

  • 绾靛悜甯冨眬 鐨?Adapter
  • Created by Tnno Wu on 2018/03/05.
    */

public class VerticalAdapter extends RecyclerView.Adapter<VerticalAdapter.VerticalViewHolder> {

private static final String TAG = VerticalAdapter.class.getSimpleName();

private Context mContext;

private List<String> mList = new ArrayList<>();

public VerticalAdapter(Context context) {
    mContext = context;
}

public void setVerticalDataList(List<String> list) {
    Log.d(TAG, "setVerticalDataList: " + list.size());

    mList = list;

    notifyDataSetChanged();
}

@NonNull
@Override
public VerticalViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.vertical_recycle_item, parent, false);
    return new VerticalViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull VerticalViewHolder holder, int position) {
    holder.tvNum.setText(position + 1 + "");
    holder.tvContent.setText(mList.get(position));
}

@Override
public int getItemCount() {
    return mList == null ? 0 : mList.size();
}

public class VerticalViewHolder extends RecyclerView.ViewHolder {

    TextView tvNum, tvContent;

    public VerticalViewHolder(View itemView) {
        super(itemView);
        tvNum = itemView.findViewById(R.id.tv_num);
        tvContent = itemView.findViewById(R.id.tv_content);
    }
}

}

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:orientation="horizontal"

    >
    <ImageView
        android:layout_width="70dp"
        android:layout_height="60dp"
        android:background="@drawable/shousuobg3"/>

    <EditText
        android:id="@+id/edit_word"

        android:layout_width="211dp"

        android:layout_height="wrap_content"

        android:textSize="15sp" />

    <Button

        android:id="@+id/button"

        android:layout_width="40dp"

        android:layout_height="40dp"
        android:background="@drawable/vns"




        />
</LinearLayout>


<android.support.v7.widget.RecyclerView

    android:id="@+id/rcv_vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:overScrollMode="never"
    android:scrollbars="none" >




</android.support.v7.widget.RecyclerView>

<TextView

    android:id="@+id/result"

    android:layout_width="match_parent"

    android:layout_height="180dp"

    android:textSize="16sp"

    />
<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/tv_num"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"

    tools:text="1"
    android:textColor="@android:color/black"/>

<TextView
    android:id="@+id/tv_content"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_margin="8dp"
    tools:text="鍐呭"
    android:textColor="@android:color/black"
    />

下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值