2012-11-09 3 views
0

: 사용자 키를 눌러 키보드의 버튼을 삭제할 때마다토큰 글고 치기 (필드) 안드로이드

enter image description here

는 글고 치기는 하나가 아닌 토큰을 삭제합니다 한 단어. 그럼, 내 질문은 : 우리는 그것과 같은 존재 컨트롤이 있습니까? 또는 그렇지 않은 경우 어떻게 사용자 정의 할 수 있는지 알고 계십니까? 참고 : 같은 100 % 필요하지 않습니다. 지금, 나는 삭제 기능에 대한 TextWatcher 또는 setKeyListener 메서드를 사용하려고 생각하고 있습니다.

도움을 주셔서 대단히 감사합니다. 그리고 나의 영어가 정말로 좋지 않기 때문에 유감스럽게 생각해 라.

답변

1

Android AOSP 이메일 클라이언트에는 사용자가하려는 것처럼 보입니다. 오픈 소스입니다.

this commit에서 Google은 사용자가 "배지"라고 부르는 칩을 "칩"이라고합니다.

당신은 그것이 내가 추측 위의 커밋에서 이러한 칩을 구현하는 데 걸리는 무엇에 대한 모든 정보를 찾을 수 있어야, 구글은 칩을 소개 처음으로 (최소한 메일)이었다, 또는 the whole source of the AOSP email client에서 :

칩을 전자 메일에 통합하십시오.

변경-ID는 : Ice037a55a169037f725a667fad7714c7e9580b86

+0

내가 너무 늦게 답장을하기 때문에 그래서 죄송합니다. 감사합니다. @cimnine. 하지만 ICS에서만 사용 가능한 것으로 보입니다. 나는 그것이 RecipientEditTextView를 사용하는 것을 본다. Android SDK에서 볼 수 없습니다. 연구 후 나는 이것을 발견했다 : https://android.googlesource.com/platform/frameworks/ex/+/refs/heads/master/chips. ICS에서만 사용 가능합니다.(아직 귀하의 의견을 따르려고 시도하지 않았습니다). 내 안드로이드 버전 3.0입니다. – gZerone

+0

죄송하지만 나는 더 좋은 대답을 드릴 수 없습니다. 나는 한동안 해결책을 찾았고 뭔가를 찾지도 못했다. 아무리해도 기존 코드를 Android 3.0으로 다시 이식하는 것을 막을 수는 없지만 직접 솔루션을 생각해 보면 더 안전하고 신속하게 진행할 수 있습니다. 왜 오픈 소스로 만들지 않겠습니까? – cimnine

+0

안녕하세요. 내 능력에서 벗어난 것 같아. 내 프로젝트에 다른 방법을 사용하고 있습니다. 나는 더 이상 Edittext를 사용하지 않았다. 그리고 저는 그것이 마치 해커처럼 생각합니다. 그래서. 나는 공개하지 말아야한다. 하지만이 링크를 찾았습니다 : http://ballardhack.wordpress.com/2011/07/25/customizing-the-android-edittext-behavior-with-spans/ 나는 그것을 아주 잘 생각하고 다른 사람들을 도울 것입니다. – gZerone

4

나는 Splitwise에서 우리의 사용을 위해 함께 TokenAutoComplete on github 넣었습니다. Android SDK에서 이와 같은 것을 찾을 수 없으므로 직접 만들었습니다.

내 컨트롤의 동작이 예상과 일치하지 않는 유일한 위치는 가장 최근에 완료된 토큰을 삭제하면 다시 단어로 바뀝니다. 다른 모든 토큰은 완전히 삭제됩니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"> 

    <TextView android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/token_background" 
     android:padding="5dp" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" /> 

</LinearLayout> 

(여기 레이아웃의 어떤 종류를 사용하거나 토큰의 이미지를 원하는 경우 이미지 뷰를 던져 수) contact_token에 대한

public class ContactsCompletionView extends TokenCompleteTextView { 
    public ContactsCompletionView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected View getViewForObject(Object object) { 
     Person p = (Person)object; 

     LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     LinearLayout view = (LinearLayout)l.inflate(R.layout.contact_token, (ViewGroup)ContactsCompletionView.this.getParent(), false); 
     ((TextView)view.findViewById(R.id.name)).setText(p.getEmail()); 

     return view; 
    } 

    @Override 
    protected Object defaultObject(String completionText) { 
     //Stupid simple example of guessing if we have an email or not 
     int index = completionText.indexOf('@'); 
     if (index == -1) { 
      return new Person(completionText, completionText.replace(" ", "") + "@example.com"); 
     } else { 
      return new Person(completionText.substring(0, index), completionText); 
     } 
    } 
} 

레이아웃 코드 : 여기

은 기본 예제 토큰 backgound에 그릴 수

<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <solid android:color="#ffafafaf" /> 
    <corners 
     android:topLeftRadius="5dp" 
     android:bottomLeftRadius="5dp" 
     android:topRightRadius="5dp" 
     android:bottomRightRadius="5dp" /> 
</shape> 

Person 객체 코드

public class Person implements Serializable { 
    private String name; 
    private String email; 

    public Person(String n, String e) { name = n; email = e; } 

    public String getName() { return name; } 
    public String getEmail() { return email; } 

    @Override 
    public String toString() { return name; } 
} 

샘플 활동

public class TokenActivity extends Activity { 
    ContactsCompletionView completionView; 
    Person[] people; 
    ArrayAdapter<Person> adapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     people = new Person[]{ 
       new Person("Marshall Weir", "[email protected]"), 
       new Person("Margaret Smith", "[email protected]"), 
       new Person("Max Jordan", "[email protected]"), 
       new Person("Meg Peterson", "[email protected]"), 
       new Person("Amanda Johnson", "[email protected]"), 
       new Person("Terry Anderson", "[email protected]") 
     }; 

     adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people); 

     completionView = (ContactsCompletionView)findViewById(R.id.searchView); 
     completionView.setAdapter(adapter); 
    } 
} 

레이아웃 코드

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <com.tokenautocomplete.ContactsCompletionView 
     android:id="@+id/searchView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</RelativeLayout>