B
B
bushmaks2018-07-24 23:03:14
Java
bushmaks, 2018-07-24 23:03:14

How to fix checkMark in CheckedTextView?

Hello, I have this list created using an adapter and a CheckdTextView, the fact is that I want to change the standard checkbox to my checkmark icon, respectively, when an element from the list is not selected, this checkmark should not be visible. I changed checkMark in CheckdTextView, as shown in the code, it changed checkboxes, but didn't add functionality, what's my mistake?
How it looks in the application:
5b5784582df34986556828.png
CheckedTextView project_cell.xml code:

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/checked_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="30dp"
    android:checked="false"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:checkMark="@drawable/done_in_list"
    android:background="#FFF"
    android:textColor="#FF000000"
    android:gravity="center_vertical"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:textAppearance="?android:attr/textAppearanceLarge" />

Code from Activity.java:
public class TodoCreateActivity extends AppCompatActivity {

    private EditText todoText;
    private ListView projectsList;
    private TextView selection;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewPump.init(ViewPump.builder()
                .addInterceptor(new CalligraphyInterceptor(
                        new CalligraphyConfig.Builder()
                                .setDefaultFontPath("fonts/OpenSans-Light.ttf")
                                .setFontAttrId(R.attr.fontPath)
                                .build()))
                .build());
        setContentView(R.layout.activity_todo_create);

        todoText = (EditText) findViewById(R.id.editText);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        final String[] projectsArray = {"Семья", "Работа", "Прочее"};

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

        projectsList = (ListView) findViewById(R.id.listView);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.projectlist_cell);

        adapter.addAll(projectsArray);
        projectsList.setAdapter(adapter);

        projectsList.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {
                String selectedItem = projectsArray[position];
                // Проверка работы выбора элемента из CheckedTextView
                selection.setText(selectedItem);
            }
        });
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_create, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (!todoText.getText().toString().equals(""))
        {

            String todoTextString = todoText.getText().toString();
            // Здесь еще не доделано
            finish();

            return true;
        }
        else
        {
            Toast toast = Toast.makeText(getApplicationContext(),
                    "Вы не ввели текст задачи!", Toast.LENGTH_SHORT);
            toast.show();
            return false;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2018-07-25
@klim76

This changed the checkboxes, but did not add functionality, what is my mistake?

did you describe this functionality or everything will know out of the box what you want from each widget

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question