EditText getSlotFromBufferedLocked error

  • Replies:1
Vlanov Mitnov
  • Forum posts: 1

Sep 28, 2016, 1:43:23 PM via Website

Hello, comrades. I am new in android development.
I need to creade listView with editText fields. I have read some articles, and I've done. But when i clicke in editText field, logcat shows me error: E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb4013880. I searched in google, but without results. I apologise for radundant code.

This is manifest.

<manifest xmlns:android="schemas.android.com/apk/res/android"
package="com.example.vmitrofanov.bluetooth_proj">

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH"/>
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission-sdk-23 android:name="android.permission.BLUETOOTH_PRIVILEGED"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

This is item layout

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

<EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:text="@string/dev_name"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_weight="0.41"
    tools:ignore="LabelFor" />

<ImageButton
    android:layout_width="wrap_content"
    app:srcCompat="@drawable/cog_wheel"
    android:id="@+id/imageButton"
    android:layout_height="wrap_content"
    android:contentDescription="@string/button_desc"
    android:onClick="onSettingButtonClicked"/>

Main layout

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

xmlns:tools="schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=" "
android:weightSum="0"
android:columnCount="3"
android:rowCount="2">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1"
    android:id="@+id/button"
    android:onClick="createBluetooth"
    android:layout_column="0"
    android:layout_row="1"
    android:layout_gravity="left"
    android:gravity="center" />

<Button
    android:layout_width="172dp"
    android:layout_height="wrap_content"
    android:text="Button 2"
    android:id="@+id/button2"
    android:layout_gravity="center"
    android:onClick="startDiscovery"
    android:layout_column="1"
    android:layout_row="1"
    android:layout_columnSpan="1"
    android:gravity="center" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 3"
    android:id="@+id/button3"
    android:onClick="startDiscovery"
    android:layout_column="2"
    android:layout_row="1"
    android:layout_columnSpan="1"
    android:layout_gravity="right"
    android:gravity="center" />

<ListView
    android:id="@+id/listView"
    android:layout_column="0"
    android:layout_row="0"
    android:layout_columnSpan="3"
    android:choiceMode="singleChoice"
    android:layout_marginLeft="0dp"
    android:layout_rowWeight="1"
    android:layout_width="match_parent"
    android:layout_height="0dp" />

Adapter class

package com.example.vmitrofanov.bluetooth_proj;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import java.util.List;

public class DevSettingAdapter extends BaseAdapter
{

public DevSettingAdapter(Context context, List<String> elems)
{
    m_context = context;
    m_elems = elems;
    m_inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public Object getItem(int i) {
    return m_elems.get(i);
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {

    final ViewHolder holder;
    if (view == null)
    {
        LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        holder = new ViewHolder();
        view = inflater.inflate(R.layout.devsetting_reg, null);
        holder.et_holder = (EditText) view.findViewById(R.id.editText);
        holder.text = m_elems.get(i);
        view.setTag(holder);
    }
    else
    {
        holder = (ViewHolder) view.getTag();
    }

    holder.et_holder.setText(m_elems.get(i));
    holder.et_holder.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            m_elems.set(1, editable.toString());
        }
    });
    return view;
}

@Override
public int getCount() {
    return m_elems.size();
}

private class ViewHolder
{
    EditText et_holder;
    String text;
}

private List<String>   m_elems;
private LayoutInflater m_inflater;
private Context m_context;

}

Main activity

package com.example.vmitrofanov.bluetooth_proj;

import android.app.Activity;
import android.app.ListActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.accessibility.AccessibilityManagerCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.Manifest;
import android.widget.Toast;

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

public class MainActivity extends AppCompatActivity {

public class MyBcReceiver extends BroadcastReceiver
{
    MyBcReceiver()
    {
        super();
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action))
        {
            int checkPermission = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION);
            Toast.makeText(context, "ACTION_DISCOVERY_STARTED" + String.valueOf(checkPermission), Toast.LENGTH_SHORT).show();

        }
        else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
        {
            Toast.makeText(context, "ACTION_DISCOVERY_FINISHED", Toast.LENGTH_SHORT).show();
        }
        else if (BluetoothDevice.ACTION_FOUND.equals(action))
        {
            Toast.makeText(context, "ACTION_FOUND", Toast.LENGTH_SHORT).show();
            BluetoothDevice dev = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            mPDev.add(dev.getName() + " " + dev.getAddress());

            mListView = (ListView) findViewById(R.id.listView);
            mListView.setAdapter(mPDev);
        }

    }
}

private static int REQUEST_BLUETOOTH = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    String[] permissions = new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
                                        Manifest.permission.ACCESS_FINE_LOCATION,
                                        Manifest.permission.BLUETOOTH,
                                        Manifest.permission.BLUETOOTH_ADMIN,
                                        Manifest.permission.BLUETOOTH_PRIVILEGED};

    ActivityCompat.requestPermissions(this, permissions, REQUEST_BLUETOOTH);

    mReceiver = new MyBcReceiver();

    IntentFilter filter = new IntentFilter();
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    registerReceiver(mReceiver, filter);

    //IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

   //  int permissionCheck = ContextCompat.checkSelfPermission(R.layout.activity_main, "android.permission.ACCESS_COARSE_LOCATION");

    List<String> lst = new ArrayList<>();
    lst.add("item1");
    lst.add("item2");
    lst.add("item3");
    lst.add("item4");
    lst.add("item5");

    DevSettingAdapter adapter = new DevSettingAdapter(this, lst);
    mListView = (ListView) findViewById(R.id.listView);
    mListView.setAdapter(adapter);

}

public void createBluetooth(View view)
{
    mDevAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mDevAdapter == null)
    {
        Toast.makeText(this, "No supported bluetooth.", Toast.LENGTH_SHORT).show();
        return;
    }

// else
// {
// Toast.makeText(this, "Bluetooth device exist.", Toast.LENGTH_SHORT).show();
// }

    if (!mDevAdapter.isEnabled())
    {
        Intent enIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enIntent, REQUEST_ENABLE_BT);
    }

// else
// {
// Toast.makeText(this, "Bluetooth already enabled", Toast.LENGTH_SHORT).show();
// }

    Set<BluetoothDevice> pairedDevices = mDevAdapter.getBondedDevices();
    if (pairedDevices.size() > 0)
    {
        mPDev.clear();
        for (BluetoothDevice dev : pairedDevices)
        {
            mPDev.add(dev.getName() + " " + dev.getAddress());
        }
    }

// if (mDevAdapter.isDiscovering())
// {
// mDevAdapter.cancelDiscovery();
// }

// if (mDevAdapter.startDiscovery())
// {
// TextView mView1 = (TextView) findViewById(R.id.textView);
// mView1.setText("Search starts OK.");
// }
}

public void startDiscovery(View view)
{
    mPDev.clear();

    mDevAdapter = BluetoothAdapter.getDefaultAdapter();

    if (mDevAdapter.isDiscovering())
    {
        mDevAdapter.cancelDiscovery();
    }

    mDevAdapter.startDiscovery();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mDevAdapter.cancelDiscovery();
    unregisterReceiver(mReceiver);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_ENABLE_BT && requestCode == RESULT_OK)
    {
        Toast.makeText(this, "Bluetooth enabled by user.", Toast.LENGTH_SHORT).show();
    }
}

// ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------

// public void onSettingButtonClicked(View view)
// {
// Context l_con = view.getContext();
// int curId = mListView.getId();
// Toast.makeText(l_con, "button: " + curId , Toast.LENGTH_SHORT).show();
// }

BroadcastReceiver mReceiver;
private BluetoothAdapter mDevAdapter = null;
private int REQUEST_ENABLE_BT = 1;

private ListView mListView = null;
private ArrayAdapter<String> mPDev;

}

— modified on Sep 28, 2016, 3:20:59 PM

Reply
Ashish Tripathi
  • Forum posts: 211

Oct 7, 2016, 11:43:08 AM via Website

tools:ignore="LabelFor" remove this then try

Reply