Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 按钮和文本视图组件的LinearLayout上的片段_Android_Android Fragments - Fatal编程技术网

Android 按钮和文本视图组件的LinearLayout上的片段

Android 按钮和文本视图组件的LinearLayout上的片段,android,android-fragments,Android,Android Fragments,我当前的代码布局目前没有片段, 我需要对状态(-/Picking/Picked)和按钮(Pick enable/disable)进行一些更改,使其成为片段,因为我需要保持状态和按钮(enable/disable)的数据始终保持最新/与数据库同步 这些应用程序和相同的数据将被少数授权用户使用。如果其中一个用户单击“拾取”按钮,则使用应用程序的其他用户、特定拾取按钮应禁用,并且状态应立即显示“拾取”,而不刷新整个布局 我对android应用程序开发非常陌生,虽然我有一些想法/逻辑,但有点困惑 以下是

我当前的代码布局目前没有片段, 我需要对状态(-/Picking/Picked)和按钮(Pick enable/disable)进行一些更改,使其成为片段,因为我需要保持状态和按钮(enable/disable)的数据始终保持最新/与数据库同步

这些应用程序和相同的数据将被少数授权用户使用。如果其中一个用户单击“拾取”按钮,则使用应用程序的其他用户、特定拾取按钮应禁用,并且状态应立即显示“拾取”,而不刷新整个布局

我对android应用程序开发非常陌生,虽然我有一些想法/逻辑,但有点困惑

以下是我当前的代码。。。 希望有人建议我在“片段”中的适当位置,这样我就可以运行线程,获取rest服务信息,然后在状态上显示最新值,并立即选择相应的按钮,而无需刷新整个布局

<LinearLayout 
    <TextView 
        android:id="@+id/code"
        .../>

    <TextView 
        android:id="@+id/name"
        .../>

    <TextView 
        android:id="@+id/qty"
        .../>

    <TextView 
        android:id="@+id/status"
        .../>

    <Button
    android:id="@+id/pickButton"
        ...
        android:text="@string/pick" />
/>

关于活动

public class blablaActivity extends ListActivity{
    @Override
    protected void onStart(){
        super.onStart();        
        new HttpRequestTask().execute();
    }

    private class HttpRequestTask extends AsyncTask<Void, Void, ArrayList<PickerItemDetail>> {
    //private SkuArrayAdapter m_adapter; 
    @Override
    protected ArrayList<PickerItemDetail> doInBackground(Void... params) {
        try {
            final String url = "http://10.0.2.2:8080/picking";
            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
            List<PickerItemDetail> resultList = Arrays.asList(restTemplate.getForObject(url, PickerItemDetail[].class));
            ArrayList<PickerItemDetail> pickerList = new ArrayList<PickerItemDetail>();
            if(resultList.size()>0){
                for(int i=0;i<resultList.size();i++){
                    PickerItemDetail pickerItemDetail = resultList.get(i);                  
                    pickerList.add(pickerItemDetail);

                }
            }

            return pickerList;
        } catch (Exception e) {
            Log.e("ListFruitActivity:doInBackground", e.getMessage(), e);
        }

        return null;
    }

    @Override
    protected void onPostExecute(ArrayList<PickerItemDetail> pickerList) {
        try{
            m_adapter = new SkuArrayAdapter(PickerItemActivity.this,pickerList);
            setListAdapter(m_adapter);
        }catch(Exception e){
            Log.e("ListFruitActivity:onPostExecute", e.getMessage(), e);

        }

    }

}


}
公共类blablaActivity扩展了ListActivity{
@凌驾
受保护的void onStart(){
super.onStart();
新建HttpRequestTask().execute();
}
私有类HttpRequestTask扩展了AsyncTask{
//专用SkuArrayAdapter m_适配器;
@凌驾
受保护的ArrayList doInBackground(无效…参数){
试一试{
最终字符串url=”http://10.0.2.2:8080/picking";
RestTemplate RestTemplate=新RestTemplate();
restemplate.getMessageConverters().add(新映射Jackson2HttpMessageConverter());
List resultList=Arrays.asList(restTemplate.getForObject(url,PickerItemDetail[].class));
ArrayList pickerList=新的ArrayList();
如果(resultList.size()>0){

对于(int i=0;i选中此选项,我觉得只是为了使您的按钮状态保持最新您不应该使用碎片我应该使用什么替代解决方案?我需要使按钮和状态保持最新感谢建议帮助我了解您的问题以及您正在尝试做什么?
public class SkuArrayAdapter extends ArrayAdapter<PickerItemDetail>{

private ArrayList<PickerItemDetail> objects;
private String currentsku;
public SkuArrayAdapter(Context context,ArrayList<PickerItemDetail> objects){
    super(context,R.layout.activity_list_fruit,objects);
    this.objects = objects;

}

public View getView(int position,View convertView,ViewGroup parent){
    // assign the view we are converting to a local variable
            View v = convertView;

            // first check to see if the view is null. if so, we have to inflate it.
            // to inflate it basically means to render, or show, the view.
            if (v == null) {
                LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = inflater.inflate(R.layout.activity_list_fruit, null);
            }

            /*
             * Recall that the variable position is sent in as an argument to this method.
             * The variable simply refers to the position of the current object in the list. (The ArrayAdapter
             * iterates through the list we sent it)
             * 
             * Therefore, i refers to the current Item object.
             */
            PickerItemDetail i = objects.get(position);

            if (i != null) {
                               TextView code = (TextView) v.findViewById(R.id.code);
                TextView name = (TextView) v.findViewById(R.id.name);
                TextView qty = (TextView) v.findViewById(R.id.qty);
                TextView status = (TextView) v.findViewById(R.id.status);
                Button btn = (Button) v.findViewById(R.id.pickButton);

                                  //some code....//

                            }
                           return v

}