Created
March 1, 2018 09:02
-
-
Save wajahatkarim3/0974de859c79da276fa6ddc69f2b3697 to your computer and use it in GitHub Desktop.
Chips View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.wajahatkarim3.chipsdemo.MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Hello World!" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" /> | |
<com.wajahatkarim3.chipsdemo.NamesCompletionView | |
android:id="@+id/phone_retv" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:hint="Enter names here..." | |
android:minHeight="58dp" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 26 | |
defaultConfig { | |
applicationId "com.wajahatkarim3.chipsdemo" | |
minSdkVersion 16 | |
targetSdkVersion 26 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation 'com.android.support:appcompat-v7:26.1.0' | |
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'com.android.support.test:runner:1.0.1' | |
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | |
compile "com.splitwise:tokenautocomplete:2.0.8@aar" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wajahatkarim3.chipsdemo; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.MultiAutoCompleteTextView; | |
import com.android.ex.chips.RecipientEditTextView; | |
import com.tokenautocomplete.TokenCompleteTextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final NamesCompletionView namesView = findViewById(R.id.phone_retv); | |
namesView.setTokenLimit(10); | |
namesView.setTokenListener(new TokenCompleteTextView.TokenListener<String>() { | |
@Override | |
public void onTokenAdded(String token) { | |
} | |
@Override | |
public void onTokenRemoved(String token) { | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wajahatkarim3.chipsdemo; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.TextView; | |
import com.tokenautocomplete.TokenCompleteTextView; | |
public class NamesCompletionView extends TokenCompleteTextView<String> { | |
public NamesCompletionView(Context context, AttributeSet attributeSet) | |
{ | |
super(context, attributeSet); | |
} | |
@Override | |
protected View getViewForObject(String name) { | |
LayoutInflater l = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE); | |
TextView view = (TextView) l.inflate(R.layout.simple_name_layout, (ViewGroup) getParent(), false); | |
view.setText(name); | |
return view; | |
} | |
@Override | |
protected String defaultObject(String completionText) { | |
return completionText; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<TextView | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/name" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textSize="12sp" | |
android:maxLines="1" | |
android:padding="5dp" | |
tools:text="Glenda Jönsson" | |
android:layout_margin="3dp"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment