I want to review the selected item from listview, provided that when filtering, the selected visible element is selected
This code works well if the item is selected without filtering.
If the filtering process is complete, it will display elements that are not visible in the same position
private List<string> itemlist;
listviewa.ItemClick += Listnames_ItemClick;
private void Listnames_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string itemcheck = itemlist[e.Position].ToString();
Toast.MakeText(Activity, itemcheck, ToastLength.Short).Show();
}
//filter
void _SV_QueryTextChange(object sender, Android.Support.V7.Widget.SearchView.QueryTextChangeEventArgs e)
{
_adapter.Filter.InvokeFilter(e.NewText);
}
i changed the process
enter code here
private List itemlist;
listviewa.ItemClick += Listnames_ItemClick;
private void Listnames_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string itemcheck = itemlist[e.Position].ToString();
Toast.MakeText(Activity, itemcheck, ToastLength.Short).Show();
}
//filter
void _SV_QueryTextChange(object sender, Android.Support.V7.Widget.SearchView.QueryTextChangeEventArgs e)
{
_adapter.Filter.InvokeFilter(e.NewText);
}
Related
I have a PopUpWindowShowAction that operates on the current record.
If there is no current record then I want the action disabled.
This is because if there is no record the PopUpWindowShowAction will fail.
Here is my simplified controller
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using System;
using System.Linq;
using System.Windows.Forms;
namespace MyNamespace
{
public partial class JobWorkflowController : ViewController
{
PopupWindowShowAction actWorkflow;
public JobWorkflowController()
{
TargetObjectType = typeof(IWorkflow);
actWorkflow = new PopupWindowShowAction(this, "Workflow", "Admin")
{ AcceptButtonCaption = string.Empty, ActionMeaning = ActionMeaning.Accept, CancelButtonCaption = null, Caption = "Workflow", ConfirmationMessage = null, ImageName = "Workflow", Shortcut = "F7", ToolTip = null };
actWorkflow.CustomizePopupWindowParams += actWorkflow_CustomizePopupWindowParams_1;
actWorkflow.Execute += actWorkflow_Execute_1;
actWorkflow.Cancel += actWorkflow_Cancel;
}
private void actWorkflow_CustomizePopupWindowParams_1(object sender, CustomizePopupWindowParamsEventArgs e)
{
if (View.CurrentObject is not IWorkflow wf)
{
// causes an error because the view is not set
return;
}
// code to create the popup view
}
private void actWorkflow_Execute_1(object sender, PopupWindowShowActionExecuteEventArgs e)
{
// code
}
private void actWorkflow_Cancel(object sender, EventArgs e)
{
// code
}
protected override void OnActivated()
{
base.OnActivated();
View.CurrentObjectChanged += View_CurrentObjectChanged;
View_CurrentObjectChanged(View, new EventArgs());
}
private void View_CurrentObjectChanged(object sender, EventArgs e)
{
actWorkflow.Enabled["HasCurrent"]= View.CurrentObject != null;
}
protected override void OnDeactivated()
{
View.CurrentObjectChanged -= View_CurrentObjectChanged;
base.OnDeactivated();
}
}
}
The View_CurrentObjectChanged event fires but the action does not disable.
[Update]
I tried Michael's suggestion but the action des not disable.
Put this in your constructor
actWorkflow.SelectionDependencyType = SelectionDependencyType.RequireSingleObject
And it will only be active when a single object is selected. If you'd like to have one or more objects selected it's:
actWorkflow.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
You'll have no need to subscribe to the CurrentObjectChanged event.
I am trying to retrieve data from Firebase Database and set them to text view. My database has different multiple child data. I want to retrieve all child in a single activity like globally. I have a different card view click in the main activity. when I click on any item it does not show the same child data with related that item. It shows single child data on every item click. How can I get them in a signal Activity on card view click? I am new to Android and I have tried multiple answers here, but failed. Can anyone help me with this?
public class GlobalActivity extends AppCompatActivity
RecyclerView mRecyclerView;
List<User> myUserList;
User mUser;
ProgressDialog progressDialog;
private DatabaseReference db;
private ValueEventListener eventListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_global);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Please wait its loding..");
mRecyclerView = (RecyclerView) findViewById(R.id.farazList);
GridLayoutManager gridLayoutManager = new GridLayoutManager(AhmedFarazActivity.this, 1);
mRecyclerView.setLayoutManager(gridLayoutManager);
myUserList = new ArrayList<>();
final ReAdapter reAdapter = new ReAdapter(GlobalActivity.this, myUserList);
mRecyclerView.setAdapter(reAdapter);
db = FirebaseDatabase.getInstance().getReference().child("Spinner").child("US");
progressDialog.show();
eventListener = db.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
myUserList.clear();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
User userData = ds.getValue(User.class);
myUserList.add(userData);
}
reAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
#Override
public void onCancelled(DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}
}
Handle to click
This is handler in the adapter when I click on any item it does not show the same child data with related that item. It shows single child data on every item click.
#Override
public void onBindViewHolder(#NonNull MyHolder holder, int position) {
// Hide data
holder.nameText.setText(models.get(position).getName());
holder.img.setImageResource(models.get(position).getImg());
holder.setItemClickListener(new ItemClickListener() {
#Override
public void onItemClick(View view, int pos) {
//Go to UK Item to show UK data
if (models.get(pos).getName().equals("US")){
//Start Display Activity on click
Toast.makeText(c, "US", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(c, GlobalActivity.class);
c.startActivity(intent);
}
//Go to UK Item to show UK data
if (models.get(pos).getName().equals("UK")){
//Start System Info Activity on click
Toast.makeText(c, "UK", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(c, GlobalActivity.class);
c.startActivity(intent);
}
}
});
}
Now i figure out my solution
I add just Intent.putExtra("data","1"); in every handler click
#Override
public void onBindViewHolder(#NonNull MyHolder holder, int position) {
// Hide data
holder.nameText.setText(models.get(position).getName());
holder.img.setImageResource(models.get(position).getImg());
holder.setItemClickListener(new ItemClickListener() {
#Override
public void onItemClick(View view, int pos) {
//Go to UK Item to show UK data
if (models.get(pos).getName().equals("US")){
//Start Display Activity on click
Toast.makeText(c, "US", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(c, GlobalActivity.class);
intent.putExtra("data","1");
c.startActivity(intent);
}
//Go to UK Item to show UK data
if (models.get(pos).getName().equals("UK")){
//Start System Info Activity on click
Toast.makeText(c, "UK", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(c, GlobalActivity.class);
intent.putExtra("data","2");
c.startActivity(intent);
}
}
});
}
In GlobalActivity i create a method for data
initialize data(); inside onCreate
public class GlobalActivity extends AppCompatActivity
RecyclerView mRecyclerView;
List<User> myUserList;
User mUser;
ProgressDialog progressDialog;
private DatabaseReference db;
private ValueEventListener eventListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_global);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Please wait its loding..");
mRecyclerView = (RecyclerView) findViewById(R.id.farazList);
GridLayoutManager gridLayoutManager = new GridLayoutManager(AhmedFarazActivity.this, 1);
mRecyclerView.setLayoutManager(gridLayoutManager);
myUserList = new ArrayList<>();
final ReAdapter reAdapter = new ReAdapter(GlobalActivity.this, myUserList);
mRecyclerView.setAdapter(reAdapter);
data();
progressDialog.show();
eventListener = db.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
myUserList.clear();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
User userData = ds.getValue(User.class);
myUserList.add(userData);
}
reAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
#Override
public void onCancelled(DatabaseError databaseError) {
progressDialog.dismiss();
}
});
}
method for getting
public void data() {
String data = getIntent().getStringExtra("data");
if (data.equals("1")) {
db = FirebaseDatabase.getInstance().getReference().child("Spinner").child("India");
db.keepSynced(true);
} else if (data.equals("2")) {
db = FirebaseDatabase.getInstance().getReference().child("Spinner").child("Pak");
db.keepSynced(true);
} else if (data.equals("3")) {
db = FirebaseDatabase.getInstance().getReference().child("Spinner").child("UK");
db.keepSynced(true);
}
}
If I have created a deep link using the branch.io that opens a specific screen in my app. If this link is also available in my app and a user clicks on it, will it open my screen? or it will do nothing as the link I am trying to open from the app is pointing to the same app?
When you click on a Branch link within a webView in your App, you will have to handle the routing to the specific Activity, after reading the Branch link parameters.
Here is a sample Activity which contains a webView and and shows a couple of Branch links. When you click on a link in the webView it reopens the webview and displays the link parameters in a Toast message if a Branch link is clicked
public class MainActivity extends AppCompatActivity {
private WebView webView_;
private Button button_;
private String TAG = "WebViewController";
private Context context_;
private static final String URL_TO_LOAD = "https://evangelosg.github.io/index.html";
private static final String BRANCH_LINK_TO_LOAD = "https://ere6.app.link/b6sS0gsCfG";
#Override
protected void onNewIntent(Intent intent) {
Log.d("WebView", "onNewIntent");
setIntent(intent);
}
#Override
protected void onResume() {
super.onResume();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
Log.d(TAG, referringParams.toString());
Toast.makeText(context_, referringParams.toString(), Toast.LENGTH_LONG).show();
if (referringParams.has(BundleExtraKeys.CLICKED_BRANCH_LINK)) {
try {
boolean clickedBranchLink = referringParams.getBoolean(BundleExtraKeys.CLICKED_BRANCH_LINK);
if (clickedBranchLink) {
//do stuff!
}
} catch (JSONException e) {
Log.d("BranchTrends", e.getMessage());
}
}
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
#Override
protected void onStart() {
super.onStart();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context_ = this;
setContentView(R.layout.activity_main);
webView_ = (WebView) findViewById(R.id.webView);
webView_.setWebViewClient(new BranchWebViewController("app.link", MainActivity.class));
webView_.loadUrl(URL_TO_LOAD);
button_ = (Button) findViewById(R.id.button);
button_.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra("branch", BRANCH_LINK_TO_LOAD);
customTabsIntent.intent.putExtra("branch_force_new_session", true);
finish();
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(BRANCH_LINK_TO_LOAD));
}
});
}
public class BranchWebViewController extends WebViewClient {
private String myDomain_;
private Class activityToLaunch_;
BranchWebViewController(#NonNull String myDomain, Class activityToLaunch) {
myDomain_ = myDomain;
activityToLaunch_ = activityToLaunch;
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
if (url.contains(myDomain_)) {
Intent i = new Intent(view.getContext(), activityToLaunch_);
i.putExtra("branch", url);
i.putExtra("branch_force_new_session", true);
finish();
startActivity(i);
} else {
view.loadUrl(url);
}
return true;
}
}
}
Once you read the link parameters you can route to the appropriate Activity based on the link parameters.
I have a customer list. First time it renders with all customers, then I added a filter to list only new customers. Modified the source items with new customers. But it is not rendering in the view. Adapter constructor is called with new set of array. But it is not invoking the method public override int ItemCount. This page will get rendered on screen lock and unlock of device. Please help me here
public class RecyclerViewRenderer : ViewRenderer<RecyclerViewList, RecyclerView>
{
.........
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == RecyclerViewList.ItemsProperty.PropertyName)
{
var items = (Element as RecyclerViewList).Items;
if (items != null)
{
adapter = new RecyclerViewAdapter(items);
adapter.ItemClickEvent += OnItemClick;
adapter.PopUpClickEvent += OnPopUpClick;
recyclerViewCustomers.SetAdapter(adapter);
adapter.NotifyDataSetChanged();
// Task.Delay(500);
}
}
}
......
}
I'm new to android development and I have been struggling to parse more than one tag at a time and display it in a ListView.
I'm using SAX parser, here is my RssParseHandler code.
public class RssParseHandler extends DefaultHandler {
private List<RssItem> rssItems;
private RssItem currentMessage;
//private StringBuilder builder;
private boolean parseLink;
private boolean parseTitle;
private boolean parseDate;
private boolean parseDes;
public RssParseHandler() {
rssItems = new ArrayList();
}
public List<RssItem> getItems() {
return this.rssItems;
}
#Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
super.startElement(uri, localName, name, attributes);
if (localName.equalsIgnoreCase("item")) {
this.currentMessage = new RssItem();
} else if (localName.equalsIgnoreCase("title")) {
//currentMessage.setTitle(builder.toString());
parseTitle = true;
} else if (localName.equalsIgnoreCase("link")) {
//currentMessage.setLink(builder.toString());
parseLink = true;
} else if (localName.equalsIgnoreCase("description")) {
//currentMessage.setDescription(builder.toString());
parseDes = true;
} else if (localName.equalsIgnoreCase("pubDate")) {
//currentMessage.setDate(builder.toString());
parseDate = true;
}
//parsing enclosure tag
else if ("enclosure".equals(localName)) {
// Get tags attributes number
int attrsLength = attributes.getLength();
for (int i = 0; i < attrsLength; i++) {
String attrName = attributes.getQName(i); // attribute name
if ("url".equals(attrName)) // This tag has only one attribute but it is better to check it name is correct
currentMessage.getLink();
}
}
}
#Override
public void endElement(String uri, String localName, String name)
throws SAXException {
super.endElement(uri, localName, name);
if (this.currentMessage != null) {
if (localName.equalsIgnoreCase("item")) {
rssItems.add(currentMessage);
//currentMessage = null;
} else if (localName.equalsIgnoreCase("link")) {
//currentMessage.setLink(builder.toString());
//parseLink = false;
} else if (localName.equalsIgnoreCase("description")) {
//currentMessage.setDescription(builder.toString());
//parseDes = false;
} else if (localName.equalsIgnoreCase("pubDate")){
//currentMessage.setDate(builder.toString());
parseDate = false;
} else if (localName.equalsIgnoreCase("title")) {
//currentMessage.setTitle(builder.toString());
parseTitle = false;
}
//builder.setLength(0);
}
}
#Override
public void characters(char[] ch, int start, int length)
throws SAXException {
super.characters(ch, start, length);
//builder.append(ch, start, length);
if (parseTitle) {
if (currentMessage != null)
currentMessage.setTitle(new String(ch, start, length));
} else if (parseLink) {
if (currentMessage != null) {
currentMessage.setLink(new String(ch, start, length));
//parseLink = false;
}
} else if (parseDes) {
if (currentMessage != null)
currentMessage.setDescription(new String(ch, start, length));
//parseLink = false;
} else if (parseDate) {
if (currentMessage != null) {
currentMessage.setDate(new String(ch, start, length));
//currentMessage.setDate(new String(ch, start, length));
//parseDesc = false;
}
}
}
}
Here is the code for the Listview:
public class ReaderAppActivity extends Fragment {
private ReaderAppActivity local;
private ListView mList;
/**
* This method creates main application view
*/
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
// Set view
//setContentView(R.layout.fragment_rss);
local = this;
//int position = getArguments().getInt("position");
// String url = getArguments().getString("url");
// List of rivers
String[] menus = getResources().getStringArray(R.array.menus);
// Creating view corresponding to the fragment
View v = inflater.inflate(R.layout.fragment_rss, container, false);
// Set reference to this activity
//local = this;
GetRSSDataTask task = new GetRSSDataTask();
// Start download RSS task
task.execute("http://thechurchofwhatshappeningnow.libsyn.com/rss");
//task.execute(url);
// Debug the thread name
Log.d("ITCRssReader", Thread.currentThread().getName());
//mList = (ListView) findViewById(R.id.rssListMainView);
return v;
}
private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem> > {
#Override
protected List<RssItem> doInBackground(String... urls) {
// Debug the task thread name
Log.d("ITCRssReader", Thread.currentThread().getName());
try {
// Create RSS reader
RssReader rssReader = new RssReader(urls[0]);
// Parse RSS, get items
return rssReader.getItems();
} catch (Exception e) {
Log.e("ITCRssReader", e.getMessage());
}
return null;
}
#Override
protected void onPostExecute(List<RssItem> result) {
// Get a ListView from main view
ListView mList = (ListView) getView().findViewById(R.id.rssListMainView);
// Create a list adapter
ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),R.layout.rss_text, result);
//ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),R.layout.fragment_rss, result);
// Set list adapter for the ListView
mList.setAdapter(adapter);
// Set list view item click listener
mList.setOnItemClickListener(new ListListener(result, getActivity()));
}
}
}
What am I doing wrong? I can't figure it out. I would like to parse, the link, description, pubDate, and pass them into the ListView. Ideally I would only display the title and episode number in the listview, and pass the other tags into String, so I can display them when I click an item in the listView.
I've created another class called SingleMenuItem to be called when I click an item in the ListView, it's just filler code right now, it does not display anything because the items aren't parsed.
Any help would be appreciated. Here is a RSS link to the feed:
public class SingleMenuItem extends Activity {
// XML node keys
static final String KEY_NAME = "name";
static final String KEY_DATE = "pubdate";
static final String KEY_DESC = "description";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
// getting intent data
Intent in = getIntent();
// Get XML values from previous intent
String name = in.getStringExtra(KEY_NAME);
String date = in.getStringExtra(KEY_DATE);
String description = in.getStringExtra(KEY_DESC);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblDate = (TextView) findViewById(R.id.date_label);
TextView lblDesc = (TextView) findViewById(R.id.description_label);
lblName.setText(name);
lblDate.setText(date);
lblDesc.setText(description);
}
}
Here is the code for my ReaderAppActivty that puts the results of the parsing into the ListView:
public class ReaderAppActivity extends Fragment {
private ReaderAppActivity local;
private ListView mList;
/**
* This method creates main application view
*/
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
// Set view
//setContentView(R.layout.fragment_rss);
local = this;
//int position = getArguments().getInt("position");
// String url = getArguments().getString("url");
// List of rivers
String[] menus = getResources().getStringArray(R.array.menus);
// Creating view corresponding to the fragment
View v = inflater.inflate(R.layout.fragment_rss, container, false);
// Set reference to this activity
//local = this;
GetRSSDataTask task = new GetRSSDataTask();
// Start download RSS task
task.execute("http://thechurchofwhatshappeningnow.libsyn.com/rss");
//task.execute(url);
// Debug the thread name
Log.d("ITCRssReader", Thread.currentThread().getName());
//mList = (ListView) findViewById(R.id.rssListMainView);
return v;
}
private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem> > {
#Override
protected List<RssItem> doInBackground(String... urls) {
// Debug the task thread name
Log.d("ITCRssReader", Thread.currentThread().getName());
try {
// Create RSS reader
RssReader rssReader = new RssReader(urls[0]);
// Parse RSS, get items
return rssReader.getItems();
} catch (Exception e) {
Log.e("ITCRssReader", e.getMessage());
}
return null;
}
#Override
protected void onPostExecute(List<RssItem> result) {
// Get a ListView from main view
ListView mList = (ListView) getView().findViewById(R.id.rssListMainView);
// Create a list adapter
ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),R.layout.rss_text, result);
//ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(getActivity(),R.layout.fragment_rss, result);
// Set list adapter for the ListView
mList.setAdapter(adapter);
// Set list view item click listener
mList.setOnItemClickListener(new ListListener(result, getActivity()));
}
}
}
Based on the amount of commented-out code in your RssParseHandler, you've clearly been struggling with this for a bit, and some early attempts were closer to right than what you've got now.
The issue with your current code appears to be that you're not consistently resetting the booleans that drive which part of the item you're setting. Debugging through it, I saw it setting a date into the link field at some point.
But you're actually doing some of that setting in the wrong method, as the characters method doesn't necessarily give you the full contents of the tag. You need to use a Stringbuilder, and I can see from commented-out code that you tried that at some point.
If you collect the text in a stringbuilder and do all the setting in the endElement method, you don't really need the booleans at all, as the endElement method has knowledge of which tag you're ending.
Here's a working version that's perhaps not too far from something you had at some point but which gets rid of all those flag fields.
public class RssParseHandler extends DefaultHandler {
private List<RssItem> rssItems;
private RssItem currentMessage;
private StringBuilder builder;
public RssParseHandler() {
rssItems = new ArrayList<>();
builder = new StringBuilder();
}
public List<RssItem> getItems() {
return this.rssItems;
}
#Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
super.startElement(uri, localName, name, attributes);
builder.setLength(0);
if (localName.equalsIgnoreCase("item")) {
this.currentMessage = new RssItem();
}
}
#Override
public void endElement(String uri, String localName, String name)
throws SAXException {
super.endElement(uri, localName, name);
if (this.currentMessage != null) {
if (localName.equalsIgnoreCase("item")) {
rssItems.add(currentMessage);
currentMessage = null;
} else if (localName.equalsIgnoreCase("link")) {
currentMessage.setLink(builder.toString());
} else if (localName.equalsIgnoreCase("description")) {
currentMessage.setDescription(builder.toString());
} else if (localName.equalsIgnoreCase("pubDate")){
currentMessage.setDate(builder.toString());
} else if (localName.equalsIgnoreCase("title")) {
currentMessage.setTitle(builder.toString());
}
}
}
#Override
public void characters(char[] ch, int start, int length)
throws SAXException {
super.characters(ch, start, length);
builder.append(ch, start, length);
}
}