<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/window_foreground">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="@dimen/appbar_resting"
android:theme="@style/AppTheme.NoActionBar">
<com.ujjwal.univhub.components.SearchView
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/fragment_university_lsit"></include>
</FrameLayout>
app_bar_main.xml Here searchView is customFrameLayout.I used this xml file in my main activity xml file.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
layout="@layout/floating_action_group"/>
</FrameLayout>
This is activity_main.xml
public class SearchView extends FrameLayout implements AdapterView.OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SuggestionAdapter.ViewHolder viewHolder = (SuggestionAdapter.ViewHolder)view.getTag();
University selectedUniversity = viewHolder.getUniversity();
String sendData = FilterBuilder.createCodeFilter(selectedUniversity.getCode()).toJson();
//may occure error here
Log.d("serach by name", "onItemClick: error");
KeyListener listener = new KeyListener((BaseActivity)getContext());//error thrown here.
listener.onClicked(sendData, Properties.LOCALHOST + Properties.UNIVERSITY_CODE);
queryInput.setText(selectedUniversity.getName());
suggestionAdapter.clear();
suggestionAdapter.notifyDataSetChanged();
}
}
In my MainActivity
setContentView(R.layout.activity_main);
java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to com.ujjwal.univhub.BaseActivity
My can't i cast context to the activity hosting the view.